feat(router): add "onSameUrlNavigation" router configuration option (#19463)

PR Close #19463
This commit is contained in:
vsavkin
2017-10-19 18:32:50 -04:00
committed by Matias Niemelä
parent adab4f3e49
commit d3211a2468
4 changed files with 43 additions and 12 deletions

View File

@ -129,12 +129,15 @@ export class RouterModule {
* Creates a module with all the router providers and directives. It also optionally sets up an
* application listener to perform an initial navigation.
*
* Options:
* Options (see {@link ExtraOptions}):
* * `enableTracing` makes the router log all its internal events to the console.
* * `useHash` enables the location strategy that uses the URL fragment instead of the history
* API.
* * `initialNavigation` disables the initial navigation.
* * `errorHandler` provides a custom error handler.
* * `preloadingStrategy` configures a preloading strategy (see {@link PreloadAllModules}).
* * `onSameUrlNavigation` configures how the router handles navigation to the current URL. See
* {@link ExtraOptions} for more details.
*/
static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders {
return {
@ -267,6 +270,14 @@ export interface ExtraOptions {
* Configures a preloading strategy. See {@link PreloadAllModules}.
*/
preloadingStrategy?: any;
/**
* Define what the router should do if it receives a navigation request to the current URL.
* By default, the router will ignore this navigation. However, this prevents features such
* as a "refresh" button. Use this option to configure the behavior when navigating to the
* current URL. Default is 'ignore'.
*/
onSameUrlNavigation?: 'reload'|'ignore';
}
export function setupRouter(
@ -299,6 +310,10 @@ export function setupRouter(
});
}
if (opts.onSameUrlNavigation) {
router.onSameUrlNavigation = opts.onSameUrlNavigation;
}
return router;
}