From 5c4e4d5d36e2a2de128efc27e3eb01bf3ebcf31b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 28 Jun 2018 11:45:38 -0400 Subject: [PATCH] only navigate if route is found - fixes #279 --- src/runtime/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/runtime/index.ts b/src/runtime/index.ts index 5185385..b2308f6 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -208,7 +208,11 @@ function handle_popstate(event: PopStateEvent) { if (event.state) { const url = new URL(window.location.href); const target = select_route(url); - navigate(target, event.state.id); + if (target) { + navigate(target, event.state.id); + } else { + window.location.href = window.location.href; + } } else { // hashchange cid = ++uid; @@ -286,7 +290,7 @@ export function init(opts: { App: ComponentConstructor, target: Node, routes: Ro history.replaceState({ id: uid }, '', href); const target = select_route(new URL(window.location.href)); - return navigate(target, uid); + if (target) return navigate(target, uid); }); }