Bard mobx router

Bard mobx router

  • Github

›Plugins

About Bard router

  • Philosophy
  • Getting started

Router and routes

  • Route specific hooks
  • Router hooks

React UI Components

  • <Route/>
  • <Link/>

Plugins

  • Scroll plugin
  • Window title plugin
  • Html5 history plugin

How to's

  • How-to's / FAQ

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 a function.
  • if it's a function, it will be called with the router as argument.

Example

  1. configure the routes
{
  '/some-page': {
    windowTitlePlugin: 'Some page',
  },
  '/some-other-page': {
    windowTitlePlugin: () => `Some other page - ${getSomeValue()}`,
  },
}
  1. 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

← Scroll pluginHtml5 history plugin →
  • How to use the window title plugin?
  • Example
  • windowTitlePlugin options
Bard mobx router
Docs
Getting Started
Community
Who is using this?Chat on Gitter
More
GitHub
Copyright © 2023 Aodev