Angular router: how to replace param?

To navigate to particular link from current url, you can do something like this, constructor(private route: ActivatedRoute, private router: Router){} ngOnInit() { this.route.params.subscribe(params => { // PARAMS CHANGED .. let id = params[‘projectid’]; }); } navigate(){ this.router.navigateByUrl(this.router.url.replace(id, newProjectId)); // replace parameter of navigateByUrl function to your required url } On ngOnInit function, we have subscribed … Read more

Navigating to the same route not refreshing the component?

If only the params has changes the component itself won’t be initialize again. But you can subscribe to changes in the parameters that you send. For example on ngOnInit method you can do something like this: ngOnInit() { this.sub = this.route.params.subscribe(params => { const term = params[‘term’]; this.service.get(term).then(result => { console.log(result); }); }); }

How do I detect user navigating back in Angular2?

EDIT Please don’t do this. The official docs say “This class should not be used directly by an application developer. Instead, use Location.” Ref: https://angular.io/api/common/PlatformLocation It’s possible to use PlatformLocation which has onPopState listener. import { PlatformLocation } from ‘@angular/common’ (…) constructor(location: PlatformLocation) { location.onPopState(() => { console.log(‘pressed back!’); }); } (…)

Angular2 – Redirect to calling url after successful login

There’s a tutorial in the Angular Docs, Milestone 5: Route guards. One possible way to achieve this is by using your AuthGuard to check for your login status and store the url on your AuthService. AuthGuard import { Injectable } from ‘@angular/core’; import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from ‘@angular/router’; import { AuthService } … Read more

How can I improve load performance of Angular2 apps?

A single page application generally takes more time while loading as it loads all necessary things at once. I had also faced same problem and my team has optimized our project from loading in 8 seconds to 2 seconds by using following methods. Lazy loading a module : Lazy loading modules helps to decrease the … Read more