Closed thunderkid closed 6 years ago
+1 on this question as well. thanks
There currently isn't a way to do this. But you can use preventDefault()
as a workaround. The window always fires the hashchange
or popstate
events, but you can specify whether or not you want the router to continue. @thunderkid @droplab
Do you mean something like this as a workaround?
this.router.on('hashchange', (event) => this.onPopstate(event, this.router.path()));
then
onPopstate(event, path: string) {
if (path == pathThatIJustSet)
event.preventDefault();
}
when I try this I get that event
is undefined. Thanks.
@thunderkid maybe they meant this: https://github.com/baseprime/grapnel/issues/46#issuecomment-129550677
Great library. Thanks for your work! Is there a way to set the url hash without triggering the route handlers?
I've tried path(newPath), but that triggers them just like navigate(newPath). I can imagine doing it with preventDefault() in a pretty hackish way - I'd need to have an
ignoreMatching
flag of some sort, but turning this on and off safely seems rather fragile. (eg, I'd need to clear the flag whether or not a match was found, and worry about event orders.)Is there a more efficient way to do it? Some other libraries just have a
silently
option fornavigate()
.