diff --git a/frontend/src/components/TopLevel.component.js b/frontend/src/components/TopLevel.component.js index cb7d7e3..c6d7ff3 100644 --- a/frontend/src/components/TopLevel.component.js +++ b/frontend/src/components/TopLevel.component.js @@ -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') ) { diff --git a/frontend/src/module/routing.js b/frontend/src/module/routing.js index 6dca097..b50ed0f 100644 --- a/frontend/src/module/routing.js +++ b/frontend/src/module/routing.js @@ -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)) }