![](/img/trans.png)
[英]routerLink outside of component template in Angular 2, in base html
[英]Angular 2 proper way to template a [routerLink] in a child component
在我的app.component
我有<router-outlet></router-outlet>
。
現在,在otherModule.component
內部,我嘗試應用<a [routerLink]="['home']">Home</a>
。
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import {HomeModule} from "../home/home.module";
import {OtherModule} from "../otherModule/otherModule.module";
import {RouterModule} from "@angular/router";
import {routes} from "./routes";
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HomeModule,
HttpModule,
OtherModule,
RouterModule.forRoot(routes)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import {HomeComponent} from "../login/login.component";
import {OtherComponent} from "../clickStudio/clickStudio.component";
export const routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'other', component: OtherComponent },
]
import {Component} from "@angular/core";
@Component({
selector: 'other',
template: `<a [routerLink]="['home']">Home</a>`,
styleUrls: ['./clickstudio-menu.component.scss']
})
export class OtherComponent {
}
你有沒有嘗試過
<a routerLink="home">Details</a>
要么
<a routerLink="/home">Details</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.