Skip to content

Instantly share code, notes, and snippets.

@ranwahle
Created June 16, 2019 07:04
Show Gist options
  • Save ranwahle/e325bb7800620408ba16d27fb3949234 to your computer and use it in GitHub Desktop.
Save ranwahle/e325bb7800620408ba16d27fb3949234 to your computer and use it in GitHub Desktop.
Navigate with both guard functions
async navigate(url) {
// Check if you may exit the current URL
const oldRouteData = this.routingSnapshotTreeBuilder.buildRouteTree(window.location.pathname);
try {
url = url === '/' ? url : new URL(url).pathname;
} catch (err) {
throw Error(`Cannot construct url from ${url}`)
}
this.currentSnapshot = this.routingSnapshotTreeBuilder.buildRouteTree(url);
const canGoOn = await this.canGoOn(url, this.currentSnapshot.guard, oldRouteData && oldRouteData.deactivateGuard, window.location.pathname);
if (!canGoOn) {
return;
}
history.pushState({current: url, prev: window.location.pathname}, null, url);
this.routerOutlet.setAttribute('current-url', url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment