Skip to content

Unable to connect to nav events that occur on router creation #386

Closed
@agubler

Description

@agubler

Bug

The Router uses an eventing solution that queues events that occur before there are any listeners attached, which means any events that occur on creation can still be caught afterwards by attaching a listener after. However when using the registerRouterInjector utility function, this connects to the nav event to connect to the invalidation event which means that adding a listener after registering the router that the events have already been passed to the invalidate listener.

It would be useful in these scenarios, if the registerRouterInjector function could take an existing router instance that has already had any custom events attached before registering the router as an injector in the registry.

Current Behaviour:

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);

router.on('nav', () => {
    // listener to catch the events emitted on router instantiation.
    // however these will be missed as the `registerRouterInjector`
    // has already added a listener to the `nav` event 
});

Possible Behaviour:

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

const routes = [];
const registry = new Registry();
const router = new Router();
router.on('nav', () => {
    // listener to catch the events emitted on router instantiation.
    // listening to `nav` before registering the injector means it will capture
    // events from instantiation
});
registerRouterInjector(routes, registry, { router });

An alternative, but breaking change would be to add a start method to the router that will give users a change to connect to router events before all the initial processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions