Commit f04520f5 authored by Alexandre's avatar Alexandre Committed by Clément

bugfix: default sub-routes were not activated correctly

parent a26caba3
Pipeline #2641 passed with stage
in 27 seconds
......@@ -4,9 +4,6 @@ export default class SIBRoute extends HTMLElement {
}
connectedCallback() {
this.addEventListener('click', event => this.router.navigate(this.name));
// Resetting all routers within the selected view
document.addEventListener('DOMContentLoaded', () => this.updateSubRouters());
}
get name() {
......
......@@ -2,8 +2,13 @@ export default class SIBRouter extends HTMLElement {
constructor() {
super();
window.addEventListener('popstate', () => this.display());
window.addEventListener('requestNavigation', event => this.navigate(event.detail.route, event.detail.resource, event.detail.keepURL));
window.addEventListener('DOMContentLoaded', () => this.display());
window.addEventListener('requestNavigation', ({detail}) => this.navigate(detail.route, detail.resource, detail.keepURL));
window.addEventListener('DOMContentLoaded', () => {
for (const route of this.routes) {
route.updateSubRouters();
}
this.display();
});
}
get useHash() {
return this.hasAttribute('use-hash');
......@@ -23,10 +28,7 @@ export default class SIBRouter extends HTMLElement {
if(url.startsWith(this.prefix)) {
url = url.slice(this.prefix.length);
}
if(url.startsWith('/')) {
url = url.slice(1);
}
return url;
return stripSlash(url);
}
get currentRouteName() {
return this.currentURL.split('/')[0] || this.defaultRoute;
......@@ -74,5 +76,14 @@ export default class SIBRouter extends HTMLElement {
this.display(routeName, resource);
}
}
customElements.define('sib-router', SIBRouter);
function stripSlash(str) {
if(str.startsWith('/')) {
str = str.slice(1);
}
if(str.endsWith('/')) {
str = str.slice(0, str.length - 1);
}
return str;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment