在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 {
}
答案 0 :(得分:3)
你试过吗
<a routerLink="home">Details</a>
或
<a routerLink="/home">Details</a>