replaceUrl doesn't works when using relativeTo
See original GitHub issueπ bug report
Affected Package
The issue is caused by package @angular/routerIs this a regression?
Don't know but doesn't works in any minor version of 7Description
New state is pushed in history.
When this works fine:
this.router.navigate(['/login'], { queryParams: {}, replaceUrl: true});
This doesnβt work as expected:
this.router.navigate(['.'], { relativeTo: this.route, queryParams: {}, replaceUrl: true});
or
this.router.navigate([''], { relativeTo: this.route, queryParams: {}, replaceUrl: true});
Workaround:
this.router.navigate([this.router.url.split('?')[0]], { queryParams: {}, replaceUrl: true });
π¬ Minimal Reproduction
https://stackblitz.com/edit/angular-wshy3c Test url https://angular-wshy3c.stackblitz.io/login?bob=coucou
In stackblitz there is an other error: replaceUrl
works but not relativeTo
π₯ Exception or Error
No errors in console
π Your Environment
Angular Version: Also tried in 7.2.15
Angular CLI: 7.1.4
Node: 10.7.0
OS: darwin x64
Angular: 7.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.11.4
@angular-devkit/build-angular 0.11.4
@angular-devkit/build-optimizer 0.11.4
@angular-devkit/build-webpack 0.11.4
@angular-devkit/core 7.1.4
@angular-devkit/schematics 7.1.4
@angular/router 7.1.4
@ngtools/webpack 7.1.4
@schematics/angular 7.1.4
@schematics/update 0.11.4
rxjs 6.3.3
typescript 3.1.6
webpack 4.23.1
Anything else relevant?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Using "replaceUrl" In Order To Honor The Back-Button While ...
navigateByUrl() in the constructor. // in "redirectTo" property works. // to the previous URL without getting caught in a redirect. As you canΒ ......
Read more >Angular navigate to url by replacing an existing parameter
Question: So, how do I get the parameter of my router and replace it with the current paremeter? angular.
Read more >Mastering RouterLink - Briebug Blog
With replaceUrl, we are telling the browser: "remove the previous route and URL from history once this route is activated". Let's look at...
Read more >NavigationExtras - Angular
interface NavigationExtras extends UrlCreationOptions, NavigationBehaviorOptions { // inherited from router/UrlCreationOptions relativeTo?:
Read more >RouterLink, Navigate & NavigateByUrl to Navigate Routes
Learn to navigate between the routes using the RouterLink ... then the path is relative to the parent route. ... replaceUrl: boolean
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gilsdav - Note that you can use
this.router.navigate([], { queryParams: {}, replaceUrl: true});
for your case. When the commands array is empty, the router will use thecurrentUrlTree
as the basis for navigation https://stackblitz.com/edit/angular-vxxtul https://github.com/angular/angular/blob/1237d9cbea39da36dfedc884ae36c12a04addd85/packages/router/src/create_url_tree.ts#L17-L18This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.