Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): Allow onSameUrlNavigation: 'ignore' in navigateByUrl #52265

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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