Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(router): Allow onSameUrlNavigation: 'ignore' in navigateByUrl
There are cases where the application's default behavior is 'reload' and
a certain navigation might want to override this to be `ignore` instead.
This commit allows `onSameUrlNavigation` in the `router.navigateByUrl`
to be `ignore` where it was previously restricted to only `reload`.
  • Loading branch information
atscott committed Oct 18, 2023
commit 4b882e9c0575dcaa0f3645443d6a9ce0ccc4b980
2 changes: 1 addition & 1 deletion goldens/public-api/router/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export interface Navigation {

// @public
export interface NavigationBehaviorOptions {
onSameUrlNavigation?: Extract<OnSameUrlNavigation, 'reload'>;
onSameUrlNavigation?: OnSameUrlNavigation;
replaceUrl?: boolean;
skipLocationChange?: boolean;
state?: {
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ export interface NavigationBehaviorOptions {
* @see {@link OnSameUrlNavigation}
* @see {@link RouterConfigOptions}
*/
onSameUrlNavigation?: Extract<OnSameUrlNavigation, 'reload'>;
onSameUrlNavigation?: OnSameUrlNavigation;

/**
* When true, navigates without pushing a new state into history.
Expand Down
27 changes: 27 additions & 0 deletions packages/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ describe('Integration', () => {
]);
});

it('should override default onSameUrlNavigation with extras', async () => {
TestBed.configureTestingModule({
providers: [
provideRouter([], withRouterConfig({onSameUrlNavigation: 'reload'})),
]
});
const router = TestBed.inject(Router);
router.resetConfig([
{path: '', component: SimpleCmp},
{path: 'simple', component: SimpleCmp},
]);

const events: (NavigationStart|NavigationEnd)[] = [];
router.events.subscribe(e => onlyNavigationStartAndEnd(e) && events.push(e));

await router.navigateByUrl('/simple');
await router.navigateByUrl('/simple');
expectEvents(events, [
[NavigationStart, '/simple'], [NavigationEnd, '/simple'], [NavigationStart, '/simple'],
[NavigationEnd, '/simple']
]);

events.length = 0;
await router.navigateByUrl('/simple', {onSameUrlNavigation: 'ignore'});
expectEvents(events, []);
});

it('should ignore empty paths in relative links',
fakeAsync(inject([Router], (router: Router) => {
router.resetConfig([{
Expand Down