0

I am new in angularjs2 and i try to navigate route but i revived "29:20 caused by: this._router.navigate is not a function"

may code like this

import {Component} from '@angular/core';
import { Http } from '@angular/http';
import { ActivatedRoute } from '@angular/router';
import 'rxjs/add/operator/map';

@Component({
selector: 'app-user',
templateUrl: `app/user/user.component.html`
})
export class UserComponent {
constructor(private _http: Http, private _router: ActivatedRoute) { 
}

edit() {
this._router.navigate(['form']);
}
};

1 Answer 1

1

You are suppose to use Router, not ActivatedRoute to navigate.

import { Router } from '@angular/router'

...

constructor(private _http: Http, private _router: Router) {}

...

See official docs for more information

Router:

[...] Manages navigation from one component to the next.

ActivatedRoute:

A service that is provided to each route component that contains route specific information such as route parameters, static data, resolve data, global query params and the global fragment.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank for giving response. is it necessary to use Router ?
@test, yes, if you want to navigate from inside your code, Router is the way to go :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.