Window title plugin
Automatically sync the page title with the router state.
How to use the window title plugin?
- Add a
windowTitlePlugin
field to any route config. - title can be either a
string
or afunction
. - if it's a function, it will be called with the router as argument.
Example
- configure the routes
{
'/some-page': {
windowTitlePlugin: 'Some page',
},
'/some-other-page': {
windowTitlePlugin: () => `Some other page - ${getSomeValue()}`,
},
}
- register the plugin
// where you bootstrap your app_ (eg: Rootstore)
import {Router, windowTitlePlugin} from 'bard-router'
const router = new Router({...})
windowTitlePlugin.register(this.router, {
defaultTitle: 'Bard',
prefix: 'Bard - ',
})
Note, if for any reason you'd like to unregister the plugin, windowTitlePlugin.register returns a disposer function that you can just call:
const stopTitlePlugin = windowTitlePlugin.register(...)
stopTitlePlugin()
windowTitlePlugin options
- defaultTitle {string} - used as fallback for routes with undefined title
- prefix {string} - Will be put in front of all your titles. (eg: app name)
In the example above, it means that the page title would look like: Bard - Some page