Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .match(router) method that returns a route without invoking a callback #9

Merged
Merged
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
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": "^6.6.3"
},
"devDependencies": {
"dependency-check": "^2.8.0",
Expand Down