Skip to content

Conversation

@agubler
Copy link
Member

@agubler agubler commented Jun 19, 2019

Type: bug

The following has been addressed in the PR:

Description:

Currently the router uses the QueuingEvented implementation to queue events that happen before there are listeners attached.

However at the moment the registerRouterInjector helper, connects to the nav event automatically which means that any listeners added after calling registerRouterInjector will not receive the initial nav events.

This change introduces a start method to the router and an autostart property to the RouterOptions. The autostart property defaults to true which maintains the current behaviour, but when it is set to false it allows consumers to add listeners to the routing events before the router is "started". Once all the listeners have been configured, the start method is required to be called.

import Registry from '@dojo/framework/core/Registry';
import { registerRouterInjector } from '@dojo/framework/routing/RouterInjector';

const routes = [];
const registry = new Registry();
const router = registerRouterInjector(routes, registry, { autostart: false });

router.on('nav', () => {
    // add a listener that needs to catch the events
    // that occur on the initial navigation
});
router.start();

Resolves #386

Note: There are no other usages of QueuingEvented throughout framework and is not a recommended module to use externally so has been deleted from @dojo/framework/core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to connect to nav events that occur on router creation

2 participants