const routes: Routes = [ { path: '', redirectTo: '/home', pathMatch: 'full' }, { path: 'home', component: HomeComponent }, { path: 'about', component: AboutComponent }, ];
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component'; import { HomeComponent } from './home/home.component'; import { AboutComponent } from './about/about.component';
@NgModule({ imports: [ BrowserModule, RouterModule.forRoot(routes) ], declarations: [ AppComponent, HomeComponent, AboutComponent ], bootstrap: [AppComponent] }) export class AppModule { }
如果以上步骤都没有问题,那么页面应该可以正确跳转到相应的组件。
上一篇:Angular路由模块
下一篇:Angular路由模块与子模块