Inject named parameters and query parameters as "props" into your route.
import { withProps } from 'page-fu'
import page from 'page'
const Route = withProps({
enter() {
console.log(this.props.params)
console.log(this.props.query)
},
queryParamsDidChange() {
console.log('woah!');
}
})
page('/users/:userId', Route.enter)
page.exit('/users/:userId', Route.exit)
location.hash = '#/users/1?nameFilter=a'
// => { userId: "1" }
// => { nameFilter: "a" }
location.hash = '#/users/1?nameFilter=b'
// => "woah!"
Note on changes to query parameters
Unlike other libraries that choose to monkey-patch window.history
in
order to sniff changes to the URL and then re-parse the query, page-fu
expects you to use its APIs to modify the queryString where it will
internally take care of propagating those changes up to the location bar
and down to your routes.
route | Object |
Object |
A hook that will be invoked when the query parameters change through calls to Router.updateQuery or Router.replaceQuery.