2017-03-28 37 views
1

我有一個簡單的路由模塊,然後一個模板,我有聯繫。 - 第一個環節不顯示爲可點擊的鏈接,它顯示爲靜態文本。角路由器的問題 - 鏈接無法點擊

  • 第二顯示爲鏈接,只是因爲href。這是必需的嗎?

APP-routing.module.ts:

import {NgModule} from '@angular/core'; 
import {RouterModule, Routes} from '@angular/router'; 
import {AppComponent} from "./app.component"; 
import {ListComponent} from "./list/list.component" 

const appRoutes: Routes = [ 
    {path: 'List', component: ListComponent}, 
    {path: 'Home', component: AppComponent} 
]; 

@NgModule({ 
    imports: [ 
     RouterModule.forRoot(appRoutes) 
    ], 
    exports: [ 
     RouterModule 
    ] 
}) 
export class AppRoutingModule {} 

app.component.ts

import { Component } from '@angular/core'; 
import {RouterModule} from '@angular/router'; 
import { AppRoutingModule } from './app-routing.module'; 

@Component({ 
    moduleId: module.id, 
    selector: 'my-app', 
    templateUrl: './app.component.html' 
}) 
export class AppComponent { 
} 

app.component.html

<a routerLink="/List" routerLinkActive="active">List</a> | 
    <a href="./list/list.component.html" routerlink="/List" routerLinkActive="active">List</a> 

<router-outlet></router-outlet> 

回答

0

首先是不需要href,第二個應該是routerLink沒有routerlink

嘗試在你的鏈接使用下端蓋

爲什麼需要兩個鏈接指向同樣的事情

+0

我添加了在href行只是爲了測試目的,以表明HREF使鏈接點擊。使用routerLink和下蓋鏈接沒有工作。 它看起來像組件未讀取路由器模塊,或一些從屬方面沒有被加載,這是防止爲被呈現爲一個可點擊的鏈接。 – Jay