Get current route without parameters
To get current route without query parameters, you can use below mentioned single line: this.router.url.split(‘?’)[0]
To get current route without query parameters, you can use below mentioned single line: this.router.url.split(‘?’)[0]
This could be achieved by using the Router class: Using a component: import { Router, ActivatedRoute } from ‘@angular/router’; @Component({}) export class FooComponent { constructor( private _route: ActivatedRoute, private _router: Router ){} navigateToFoo(){ // changes the route without moving from the current view or // triggering a navigation event, this._router.navigate([], { relativeTo: this._route, queryParams: { … Read more
If you are using the new router (3.0.0-beta2), you can use the ActivatedRoute to navigate to relative path as follow: constructor(private router: Router, private r:ActivatedRoute) {} /// // DOES NOT WORK SEE UPDATE goToContact() { this.router.navigate([“../contacts”], { relativeTo: this.r }); } Update 08/02/2019 Angular 7.1.0 current route: /department/7/employees/45/sales the old version will do: /department/7/employees/45/sales/contacts As … Read more
Since ActivatedRoute can be reused, ActivatedRouteSnapshot is an immutable object representing a particular version of ActivatedRoute. It exposes all the same properties as ActivatedRoute as plain values, while ActivatedRoute exposes them as observables. Here is the comment in the implementation: export class ActivatedRoute { /** The current snapshot of this route */ snapshot: ActivatedRouteSnapshot; If … Read more
No From the docs : When subscribing to an observable in a component, you almost always arrange to unsubscribe when the component is destroyed. There are a few exceptional observables where this is not necessary. The ActivatedRoute observables are among the exceptions. The ActivatedRoute and its observables are insulated from the Router itself. The Router … Read more