History managers

    Or using the registerRouterInjector helper function:

    1. import Registry from '@dojo/framework/core/Registry';
    2. import { registerRouterInjector } from '@dojo/framework/routing/RouterInjector';
    3. import StateHistory from '@dojo/framework/routing/history/StateHistory';
    4. import routes from './routes';
    5. const registry = new Registry();
    6. registerRouterInjector(routes, registry);
    7. // creates and registers a router using the `StateHistory`
    8. registerRouterInjector(routes, registry, { HistoryManager: StateHistory });

    HashHistory uses the fragment identifier to process route changes, for example https://foo.com/#home would process the home as the route path. As HashHistory is the default manager, you do not need to import the module.

    StateHistory uses the browser’s history API, to manage application route changes.

    1. Re-writing the index.html request to load from the application root.
    2. Re-writing requests to load static resources (.js, .css etc) from the application root.

    Note: This machinery is included with @dojo/cli-build-app using the option (intended for development only).

    1. import { Router } from '@dojo/framework/routing/Router';
    2. import { StateHistory } from '@dojo/framework/routing/history/StateHistory';
    3. const router = new Router(config, { HistoryManager: StateHistory });

    The MemoryHistory does not rely on any browser API but keeps its own internal path state. It should not be used in production applications but is useful for testing application routing.

    1. import renderer from '@dojo/framework/core/vdom';
    2. import { registerRouterInjector } from '@dojo/framework/routing/RouterInjector';
    3. import routes from './routes';
    4. import App from './App';
    5. const registry = new Registry();
    6. // creates a router with the routes and registers the router with the registry
    7. registerRouterInjector(routes, registry);
    8. r.mount({ registry });

    These history managers work like adapters, meaning that custom history managers can be implemented by fulfilling the history manager interface.