Commit 36c5fb65 authored by Alexandre's avatar Alexandre

bugfix: route-prefix is fixed when keepURL is setup

parent ceec7547
Pipeline #2714 passed with stage
in 27 seconds
...@@ -67,7 +67,7 @@ export default class SIBRoute extends HTMLElement { ...@@ -67,7 +67,7 @@ export default class SIBRoute extends HTMLElement {
router.display(); router.display();
} }
} }
activate() { activate(keepURL=false) {
if ( if (
'HTMLDialogElement' in window && 'HTMLDialogElement' in window &&
this.view instanceof window.HTMLDialogElement this.view instanceof window.HTMLDialogElement
...@@ -80,7 +80,7 @@ export default class SIBRoute extends HTMLElement { ...@@ -80,7 +80,7 @@ export default class SIBRoute extends HTMLElement {
} }
this.setAttribute('active', ''); this.setAttribute('active', '');
this.updateResource(); this.updateResource();
this.updateSubRouters(); if (!keepURL) this.updateSubRouters();
} }
hide() { hide() {
if ( if (
......
...@@ -38,7 +38,7 @@ export default class SIBRouter extends HTMLElement { ...@@ -38,7 +38,7 @@ export default class SIBRouter extends HTMLElement {
return this.querySelectorAll('sib-route'); return this.querySelectorAll('sib-route');
} }
display(routeName = this.currentRouteName, resource) { display(routeName = this.currentRouteName, resource, keepURL=false) {
for (let route of this.routes) { for (let route of this.routes) {
if (routeName === route.name) { if (routeName === route.name) {
this.dispatchEvent( this.dispatchEvent(
...@@ -46,13 +46,13 @@ export default class SIBRouter extends HTMLElement { ...@@ -46,13 +46,13 @@ export default class SIBRouter extends HTMLElement {
detail: { route: routeName, resource }, detail: { route: routeName, resource },
}), }),
); );
route.activate(); route.activate(keepURL);
} else { } else {
route.hide(); route.hide();
} }
} }
} }
navigate(routeName = '', resource, keepURL) { navigate(routeName = '', resource, keepURL=this.hasAttribute('keep-url')) {
let route; let route;
if (routeName) { if (routeName) {
route = this.querySelector('sib-route[name="' + routeName + '"]'); route = this.querySelector('sib-route[name="' + routeName + '"]');
...@@ -77,12 +77,12 @@ export default class SIBRouter extends HTMLElement { ...@@ -77,12 +77,12 @@ export default class SIBRouter extends HTMLElement {
} }
const id = resource ? resource['@id'] : null; const id = resource ? resource['@id'] : null;
const path = route.getPath(this.prefix, routeName, id); const path = route.getPath(this.prefix, routeName, id);
if (!keepURL && !this.hasAttribute('keep-url')) { if (!keepURL) {
//update current URL //update current URL
const prefix = this.useHash ? '#' : '/'; const prefix = this.useHash ? '#' : '/';
history.pushState({}, routeName, prefix + path); history.pushState({}, routeName, prefix + path);
} }
this.display(routeName, resource); this.display(routeName, resource, keepURL);
} }
} }
customElements.define('sib-router', SIBRouter); customElements.define('sib-router', SIBRouter);
......
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