From d0425a74825b02c6756e744d3ba9c47a0afc20eb Mon Sep 17 00:00:00 2001 From: Jim Ancona Date: Fri, 7 Jul 2017 14:55:22 -0400 Subject: [PATCH] Don't include fragment identifier when matching. --- router.go | 2 +- router_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/router.go b/router.go index f157526..bef18f9 100644 --- a/router.go +++ b/router.go @@ -261,7 +261,7 @@ func (r *Router) setInitialHash() { // the appropriate handler. initial should be true iff this is the first // time the javascript is loaded on the page. func (r *Router) pathChanged(path string, initial bool) { - bestRoute, tokens, params := r.findBestRoute(path) + bestRoute, tokens, params := r.findBestRoute(strings.SplitN(path, "#", 2)[0]) // If no routes match, we throw console error and no handlers are called if bestRoute == nil { if r.Verbose { diff --git a/router_test.go b/router_test.go index 1ae3255..de9df6a 100644 --- a/router_test.go +++ b/router_test.go @@ -130,6 +130,20 @@ var routeTestCases = []struct { "qux": []string{"quux"}, }, }, + // Test hash URL matching + { + paths: []string{"/home", "/about"}, + path: "/about#foo", + expectedPath: "/about", + expectedParams: nil, + }, + // Test hash URL matching with extra hashes + { + paths: []string{"/home", "/about"}, + path: "/about#foo#bar", + expectedPath: "/about", + expectedParams: nil, + }, } func TestRouter(t *testing.T) {