Skip to content

Commit

Permalink
feat(router): implement configuration customization
Browse files Browse the repository at this point in the history
  • Loading branch information
jwx committed Aug 14, 2019
1 parent 1e8b61d commit c7f6fa5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/router/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const DefaultResources: IRegistry[] = [
NavCustomElement as unknown as IRegistry,
];

let configurationOptions: IRouterOptions = {};
let configurationCall: ((router: IRouter) => void) = (router: IRouter) => {
router.activate(configurationOptions);
};

/**
* A DI configuration object containing router resource registrations.
*/
Expand All @@ -43,7 +48,7 @@ const routerConfiguration = {
return container.register(
...DefaultComponents,
...DefaultResources,
StartTask.with(IRouter).beforeBind().call(router => router.activate()),
StartTask.with(IRouter).beforeBind().call(configurationCall),
StartTask.with(IRouter).beforeAttach().call(router => router.loadUrl()),
);
},
Expand All @@ -58,7 +63,17 @@ export const RouterConfiguration = {
/**
* Make it possible to specify options to Router activation
*/
customize(config: IRouterOptions = {}) {
customize(config?: IRouterOptions | (() => void)) {
if (config === undefined) {
configurationOptions = {};
configurationCall = (router: IRouter) => {
router.activate(configurationOptions);
};
} else if (config instanceof Function) {
configurationCall = config;
} else {
configurationOptions = config;
}
return { ...routerConfiguration };
},
...routerConfiguration,
Expand Down

0 comments on commit c7f6fa5

Please sign in to comment.