Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down