Skip to content

Commit

Permalink
Add .match(router) method that returns a route without invoking a cal…
Browse files Browse the repository at this point in the history
…lback
  • Loading branch information
marcbachmann committed Dec 28, 2017
1 parent 02e029a commit 60fcd66
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ in `opts.default` will be called. If no default handler matches, an error
will be thrown. Results return from the called handler will be returned from
this function.

### `matchedRoute = router.match(route)`
Matches a route and returns an object. The returned object contains the properties `{cb, params, route}`. This method does not invoke the callback of a route. If no route matches, the route specified in `opts.default` will be returned. If no default route matches, an error will be thrown.

Note that `router()` does not affect browser history. If you would like to
add or modify history entries when you change routes, you should use
[`history.pushState()` and `history.replaceState()`](https://developer.mozilla.org/en-US/docs/Web/API/History_API#Adding_and_modifying_history_entries)
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function Nanorouter (opts) {

emit.router = router
emit.on = on
emit.match = match
return emit

function on (routename, listener) {
Expand All @@ -48,6 +49,11 @@ function Nanorouter (opts) {
}
}
}

function match (route) {
route = pathname(route, isLocalFile)
return router.match(route)
}
}

// replace everything in a route but the pathname and hash
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "standard && npm run deps"
},
"dependencies": {
"wayfarer": "^6.5.0"
"wayfarer": "github:marcbachmann/wayfarer#add-match-method"
},
"devDependencies": {
"dependency-check": "^2.8.0",
Expand Down

0 comments on commit 60fcd66

Please sign in to comment.