Angular 2 – replace history instead of pushing

If you use router.navigate And then location.replaceState With the exact same path, you can trigger changes that usually happen, as well as replacing the history. For example, in your case: this.router.navigate([‘questions/1’]); this.location.replaceState(‘questions/1’); If you need to add parameters to the route, you can create the url for location using router.serializeUrl(router.createUrlTree(/* what you put in your … Read more

how to change page title in angular2 router

The Title service @EricMartinez points out has a setTitle() method – that’s all you need to set the title. In terms of doing it automatically on route changes, as of now there’s no built-in way of doing this other than subscribing to Router and calling setTitle() in your callback: import {RouteConfig} from ‘angular2/router’; import {Title} … Read more

Angular: append query parameters to URL

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

Angular: Cannot find a differ supporting object ‘[object Object]’

I think that the object you received in your response payload isn’t an array. Perhaps the array you want to iterate is contained into an attribute. You should check the structure of the received data… You could try something like that: getusers() { this.http.get(`https://api.github.com/search/users?q=${this.input1.value}`) .map(response => response.json().items) // <—— .subscribe( data => this.users = data, … Read more

Angular 2 Routing Does Not Work When Deployed to Http Server

This problem is solved by implementing HashLocationStrategy which adds # to all your routes. You achieve this by adding HashLocationStrategy to AppModule providers. providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}], and add the corresponding import import { HashLocationStrategy, LocationStrategy } from ‘@angular/common’; This will solve your problem. And if you don’t want to use the HashLocationStrategy, you … Read more