Add ability to resume route on page reload

master
Garrett Mills 4 years ago
parent 31ff08e6d0
commit d1c085dbf2
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -59,6 +59,7 @@ class TopLevelComponent extends Component {
async vue_on_create() {
// Listen for navigation changes.
this.router_subscription = router.subscribe((path, args) => this.on_route_change(path, args))
this.current_route = router.current_route
const url_params = new URLSearchParams(window.location.search)
if ( url_params.has('then') ) {

@ -10,6 +10,9 @@ class Router {
*/
route_args = undefined
/** The currently navigated route. */
current_route = undefined
/**
* List of callback functions listening for route changes.
* @type {function[]}
@ -22,6 +25,17 @@ class Router {
*/
history = []
/** Initialize the router and determine the current page. */
constructor() {
try {
const route = location.href.split(APP_BASE_PATH).filter(Boolean)[0].split(/[#?]/)[0]
if ( route ) {
this.navigate(route, {})
}
} catch (e) {}
}
/**
* Returns the APP_BASE_PATH of the application.
* @return {string}
@ -39,6 +53,7 @@ class Router {
this.route_args = args
this.history.push({path, args})
window.history.pushState({}, path, this.build_url(path))
this.current_route = path
this.subscribers.forEach(sub => sub(path, args))
}

Loading…
Cancel
Save