withProps Class

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.

Constructor

withProps(route: Object) -> Object

Parameters (1)

route
Object

Return Value

Object

Static Properties

props: Object

Defaults to: {}

params: Object

The parameters that the route was activated with (that is, what's found in ctx.params from page's context.)

query: Object

The current query parameters.

location: Object
pathname: String

Instance Methods