Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Angular, how to remove the current route from history on navigation?

In my app I have a category page that has links to a various product list pages. If it turns out that when you get to a product list page there is only one product then it automatically navigates to that product detail page. What I want is to remove the product list page route in the history so that when the user is on the product detail page and hits the back button they will go to the category page and not the product list page because that will just redirect them back to the detail page.

like image 226
HisDivineShadow Avatar asked Jul 19 '18 16:07

HisDivineShadow


People also ask

How can you get the current state of a route in Angular?

There are many ways by which you can get a current Route or URL in Angular. You can use the router service, location service or window object to get the path. You can also listen to changes to URL using the router event or URL change event of the location service.

How would I restrict access to routes in Angular?

Angular is completely independent of the server. We are using stateless REST API to get data. So use AuthGuard to protect the routes from unauthorized access.

What is the difference between routing and navigation in Angular?

Angular provides extensive set of navigation feature to accommodate simple scenario to complex scenario. The process of defining navigation element and the corresponding view is called Routing. Angular provides a separate module, RouterModule to set up the navigation in the Angular application.

What does RouterLink do in Angular?

RouterLink is a built-in Angular Directive that lets you link to specific routes in your app. In the SPA(single-page application), you change what the user sees by showing or hiding portions of the display that correspond to particular components, rather than going out to the server to get a new page.


1 Answers

You can use angular routers replaceUrl flag to do this. See api docs for more details here

this.router.navigate(['/view'], { replaceUrl: true }); 
like image 167
alt255 Avatar answered Sep 20 '22 13:09

alt255