Commit a26caba3 authored by Clément's avatar Clément

bugfix: update parent route without change url

parent 445480d8
Pipeline #2640 passed with stage
in 27 seconds
......@@ -2,8 +2,7 @@ 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))
window.addEventListener('requestNavigation', event => this.navigate(event.detail.route, event.detail.resource, event.detail.keepURL));
window.addEventListener('DOMContentLoaded', () => this.display());
}
get useHash() {
......@@ -38,7 +37,7 @@ export default class SIBRouter extends HTMLElement {
display(routeName = this.currentRouteName, resource) {
for(let route of this.routes){
for(let route of this.routes) {
if(routeName === route.name) {
this.dispatchEvent(new CustomEvent('navigate', {detail: {route: routeName, resource}}));
route.activate();
......@@ -47,7 +46,8 @@ export default class SIBRouter extends HTMLElement {
}
}
}
navigate(routeName = '', resource) {
navigate(routeName = '', resource, keepURL) {
if(keepURL) console.log(routeName);
let route
if(routeName) {
route = this.querySelector('sib-route[name="'+routeName+'"]');
......@@ -60,18 +60,18 @@ export default class SIBRouter extends HTMLElement {
if(this.prefix) {
const route = this.prefix.split('/').pop();
this.dispatchEvent(new CustomEvent('requestNavigation', {
detail: {route: route},
detail: {route: route, keepURL: true},
bubbles: true,
}));
}
const id = resource ? resource['@id'] : null;
const path = route.getPath(this.prefix, routeName, id);
if(!keepURL && !this.hasAttribute('keep-url')) {
//update current URL
const prefix = this.useHash ? '#' : '/';
history.pushState({}, routeName, prefix + path);
}
this.display(routeName, resource);
if(this.hasAttribute('keep-url')) return;
//update current URL
const prefix = this.useHash ? '#' : '/';
history.pushState({}, routeName, prefix + path);
}
}
......
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