Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
63895b0
buildignore inst/tmp/
gadenbuie Jun 1, 2020
72a9b39
Remove inst/tmp files
gadenbuie Jun 2, 2020
16f302b
Maintain search params and hash components of URL
gadenbuie Jun 2, 2020
b842737
Document paths(), export paths(), blaze() and as_path() S3 methods
gadenbuie Jun 2, 2020
248d965
Bump dev version, update authors
gadenbuie Jun 2, 2020
c525610
Remove search and hash components of URL when sending browser state u…
gadenbuie Jun 2, 2020
733d41a
Update documentation to use roxygen function links
gadenbuie Jun 2, 2020
e9ee710
Fix function signature of .onLoad() to appease R CMD check
gadenbuie Jun 2, 2020
01aa30b
Adds {utils} to dependencies for packageVersion()
gadenbuie Jun 2, 2020
13a3a14
Unexport param(), it's not ready yet
gadenbuie Jun 2, 2020
c355ff7
Add at least one basic test
gadenbuie Jun 2, 2020
56ba9dc
Don't update path if same as current, also send updates back to server
gadenbuie Jun 2, 2020
d2b70aa
Add app_path argument to paths()
gadenbuie Jun 8, 2020
1019a39
Redirect pages need to redirect to /app_path
gadenbuie Jun 8, 2020
e8b168c
Ensure that getPath() returns "/" when app_path is set
gadenbuie Jun 8, 2020
8d0c7cd
Prepend app_path after checking path input in pushPath
gadenbuie Jun 8, 2020
249eaae
Add path_app() and ensure pathLink() respects global app_path
gadenbuie Jun 8, 2020
7938bf2
Reset app_path if app_path = NULL when calling paths() in same session
gadenbuie Jun 8, 2020
99a4265
observePath() correctly handles leading route path slash
gadenbuie Jun 8, 2020
e8da98d
Add option to push or replace path in pushPath()
gadenbuie Jul 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Description: Simulate routing within a 'shiny' application by observering
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
Imports:
fs,
htmltools,
Expand Down
11 changes: 9 additions & 2 deletions R/url.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,25 @@ peek_params <- function() {
#' Push a new URL path or get the current path.
#'
#' @param path A character string specifying a new URL path
#' @param mode Either `"push"` or `"replace"`. If `"push"`, the default, the
#' path is pushed onto the history stack and pressing the back button in the
#' browser will redirect to the current path (before pushing the path). If
#' `"replace"`, then the pushed path will replace the current path without
#' changing the next page in the browser's back button stack.
#'
#' @param session A reactive context, defaults to
#' `shiny::getDefaultReactiveDomain()`.
#'
#' @export
pushPath <- function(path, session = getDefaultReactiveDomain()) {
pushPath <- function(path, mode = c("push", "replace"), session = getDefaultReactiveDomain()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not support replace. The replace behaviour feels unexpected or non-standard. What's the motivation for including a replace option?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was primarily for parity with mode in shiny::updateQueryString(). Secondarily, it's conceivable that an app dev might want to use replace to update the URL during some initialization process. That was my use case, it was possible to land on one page with a set of inputs that would redirect to another page and I didn't want the first state to be on the history stack.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thank you for outlining a use case. I might introduce a second function then replacePath().

path <- path_app(path)
mode <- match.arg(mode)

path <- utils::URLencode(path)

session$sendCustomMessage("blaze:pushstate", list(
path = path
path = path,
mode = mode
))
}

Expand Down
15 changes: 11 additions & 4 deletions inst/www/js/blaze.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@
})();

window.addEventListener("DOMContentLoaded", function() {
var _path = function(path) {
var _path = function(path, mode) {
const uri = pathURI(path);
if (uri) {
history.pushState(uri, null, uri);
if ((mode || "push") === "push") {
history.pushState({uri, pathname: path}, null, uri);
} else if (mode === "replace") {
history.replaceState({uri, pathname: path}, null, uri);
} else {
throw `Unknown blaze::pushPath() mode: ${mode}`;
}
sendState(path);
}
};
Expand All @@ -68,12 +74,13 @@

Shiny.addCustomMessageHandler("blaze:pushstate", function(msg) {
if (msg.path) {
_path(msg.path);
_path(msg.path, msg.mode || "push");
}
});
});

window.addEventListener("popstate", function(event) {
sendState(event.state.replace(/[?#].+$/, '') || "/");
let {pathname} = event.state || window.location;
sendState(pathname || "/");
});
})(window.jQuery, window.Shiny);
12 changes: 11 additions & 1 deletion man/pushPath.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.