Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

angular - routerlink not working in angular2

I have checked all the tutorial and didn't find, what i am doing wrong.

AppModule :

 import { BrowserModule } from '@angular/platform-browser';
 import { NgModule } from '@angular/core';
 import { FormsModule } from '@angular/forms';
 import { HttpModule } from '@angular/http';

 import { AppComponent } from './app.component';
 import {BlogComponent} from './blog/blog.component';
 import { PortfolioComponent } from './portfolio/portfolio.component';
 import { NavbarComponent } from './shared/navbar/navbar.component';
 import {TimelineComponent} from './timeline/timeline.component';
 import {HomeComponent} from './home/home.component';

 import { routing} from './app.routing';

 @NgModule({
   declarations: [
     AppComponent,
     PortfolioComponent,
     NavbarComponent,
     BlogComponent,
     TimelineComponent,
     HomeComponent
   ],
   imports: [
     BrowserModule,
     FormsModule,
     HttpModule,
     routing
   ],
   providers: [],
   bootstrap: [
     AppComponent
   ]
 })
 export class AppModule { }
 </i>

 Navigation Bar 
 <i>
 <div id="navbar" class="collapse navbar-collapse">
       <ul class="nav navbar-nav">
         <li><a routerlink="/portfolio">Portfolio</a></li>
         <li><a routerlink="/timeline">Timeline</a></li>
         <li><a routerlink="/blog">Blog</a></li>
       </ul>
       <ul class="nav navbar-nav navbar-right">
         <li><a href="#contact">Professionals</a></li>
         <li><a href="#contact">Students</a></li>
       </ul>
     </div>
 </i>

 NGModule :
 <i>
 import { BrowserModule } from '@angular/platform-browser';
 import { NgModule } from '@angular/core';
 import { FormsModule } from '@angular/forms';
 i

 import { routing} from './app.routing';

 @NgModule({

   imports: [
     BrowserModule,
     FormsModule,
     HttpModule,
     routing
   ],
   providers: [],
   bootstrap: [
     AppComponent
   ]
 })

Please check above code, anf please help me to find why routerlink is not wokring.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not sure the code you pasted is ordered correctly but I can see 2 mistakes.

First, you're setting the routerlink attribute instead of routerLink, notice it's case sensitive.

Second, I'm pretty sure you don't import RouterModule in the module with the relevant component, make sure you do that so you get access to the routerLink directive in the first place.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...