Fixed an issue where in hash mode if a route started with / it would break the navigation.
This commit is contained in:
parent
0ea44c76b9
commit
271e6e41fa
@ -252,6 +252,11 @@ class Router {
|
|||||||
static navigate(route, data = null, refresh = false) {
|
static navigate(route, data = null, refresh = false) {
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
if (Router.hashMode) {
|
if (Router.hashMode) {
|
||||||
|
//In hash mode the route can't start with /, we have to handle it here.
|
||||||
|
if (route.startsWith("/")) {
|
||||||
|
route = route.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
window.location.hash = route;
|
window.location.hash = route;
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
@ -259,13 +264,19 @@ class Router {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Router.hashMode) {
|
if (Router.hashMode) {
|
||||||
|
//In hash mode the route can't start with /, we have to handle it here.
|
||||||
|
if (route.startsWith("/")) {
|
||||||
|
route = route.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
window.location.hash = route;
|
window.location.hash = route;
|
||||||
Router.states.push(route);
|
|
||||||
} else {
|
} else {
|
||||||
window.history.pushState(route, route, route);
|
window.history.pushState(route, route, route);
|
||||||
Router.states.push(route);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Push the route to our internal states
|
||||||
|
Router.states.push(route);
|
||||||
|
|
||||||
//Create a new pushstate event and fire it.
|
//Create a new pushstate event and fire it.
|
||||||
var event = new Event("pushstate");
|
var event = new Event("pushstate");
|
||||||
event.data = data;
|
event.data = data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user