Skip to content

Commit 726530a

Browse files
atscottthePunderWoman
authored andcommitted
feat(router): Allow onSameUrlNavigation: 'ignore' in navigateByUrl (#52265)
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`. PR Close #52265
1 parent c5ead61 commit 726530a

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

goldens/public-api/router/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ export interface Navigation {
409409

410410
// @public
411411
export interface NavigationBehaviorOptions {
412-
onSameUrlNavigation?: Extract<OnSameUrlNavigation, 'reload'>;
412+
onSameUrlNavigation?: OnSameUrlNavigation;
413413
replaceUrl?: boolean;
414414
skipLocationChange?: boolean;
415415
state?: {

packages/router/src/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ export interface NavigationBehaviorOptions {
12311231
* @see {@link OnSameUrlNavigation}
12321232
* @see {@link RouterConfigOptions}
12331233
*/
1234-
onSameUrlNavigation?: Extract<OnSameUrlNavigation, 'reload'>;
1234+
onSameUrlNavigation?: OnSameUrlNavigation;
12351235

12361236
/**
12371237
* When true, navigates without pushing a new state into history.

packages/router/test/integration.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,33 @@ describe('Integration', () => {
115115
]);
116116
});
117117

118+
it('should override default onSameUrlNavigation with extras', async () => {
119+
TestBed.configureTestingModule({
120+
providers: [
121+
provideRouter([], withRouterConfig({onSameUrlNavigation: 'reload'})),
122+
]
123+
});
124+
const router = TestBed.inject(Router);
125+
router.resetConfig([
126+
{path: '', component: SimpleCmp},
127+
{path: 'simple', component: SimpleCmp},
128+
]);
129+
130+
const events: (NavigationStart|NavigationEnd)[] = [];
131+
router.events.subscribe(e => onlyNavigationStartAndEnd(e) && events.push(e));
132+
133+
await router.navigateByUrl('/simple');
134+
await router.navigateByUrl('/simple');
135+
expectEvents(events, [
136+
[NavigationStart, '/simple'], [NavigationEnd, '/simple'], [NavigationStart, '/simple'],
137+
[NavigationEnd, '/simple']
138+
]);
139+
140+
events.length = 0;
141+
await router.navigateByUrl('/simple', {onSameUrlNavigation: 'ignore'});
142+
expectEvents(events, []);
143+
});
144+
118145
it('should ignore empty paths in relative links',
119146
fakeAsync(inject([Router], (router: Router) => {
120147
router.resetConfig([{

0 commit comments

Comments
 (0)