How can I route from one component to another within an router-outlet in angular 2?
login.component.html
... login form ...
<a (click)="gotoSignup()">gotosignup</a>
<a routerlink="signup">singup</a>
<a routerlink="/signup">/singup</a>
<a routerlink="/signup/">singup</a>
<a routerlink="['signup']">[singup]</a>
<a routerlink="[/signup]">[/singup]</a>
login.component.ts
import { Component, OnInit } from '@angular/core';
import { Http, RequestOptions, Headers} from '@angular/http';
import { Router, ActivatedRoute } from '@angular/router';
export class LoginComponent implements OnInit {
constructor(public router: Router) {}
gotoSignup() {
this.router.navigate(["signup"]);
}
}
In the sample above gotosignup is working thereas the router Link is not working.
Trying to use <a [routerLink] ... ist not working eiter. It results in the following error:
Unhandled Promise rejection: Template parse errors:
Can't bind to 'routerlink' since it isn't a known property of 'a'. ("
<div class="well clearfix" style="font-size: larger;">
<a [ERROR ->][routerlink]="['/signup']">
There are similar questions however they are not working for me. The seem to refer to pre alpa versions of angular 2 eg.:
You need to add imports: [RouterModule] to the @NgModule() where your are using routerLink
It should be routerLink instead of routerlink.
Directive selectors are case sensitive (component templates in general are case sensitive)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With