question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

replaceUrl doesn't works when using relativeTo

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/router

Is this a regression?

Don't know but doesn't works in any minor version of 7

Description

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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
atscottcommented, Jul 8, 2020

@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 the currentUrlTree 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-L18

0reactions
angular-automatic-lock-bot[bot]commented, Aug 8, 2020

This 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found