router5-plugin-listeners
Version:
Router5 browser plugin
32 lines (17 loc) • 1.05 kB
Markdown
`router.subscribe` is now available and as a result listeners plugin is no longer needed.
```javascript
import listenersPlugin from 'router5-plugin-listeners'
const router = createRouter()
router.usePlugin(listenersPlugin())
```
Listeners are called with `toState` and `fromState` arguments.
`addNodeListener(name, fn)` will register a listener which will be invoked when the specified route node is the **transition node** of a route change, i.e. the intersection between deactivated and activated segments.
Listeners registered with `addListener(fn)` will be triggered on any route change, including route reloads \(_toState_ will be equal to _fromState_\). You can remove a previously added listener by using `removeListener(fn)`.
`addRouteListener(name, fn)` will register a listener which will be triggered when the router is navigating to the supplied route name.