使用Angular2开发,常会遇到路由重定向的应用场景。javascript
路由重定向的配置办法是这样的:java
{path:'要定向的路径', redirectTo:'要定向到的目标路由'}
好比某组件有个路由插件,而且一进入该组件就想要路由插件加载出内容,咱们的路由配置可能这么写:插件
routes: Routes = [ { path:'', component:'ParentComponent', children:[ { path:'', redirectTo: 'page1' },//定向 { path:'page1', component:'PageComponent1' }, { path:'page2', component:'PageComponent2' } ] } ]
若是是兄弟路由之间的定向,则相似这样:component
routes: Routes = [ { path:'', redirectTo: 'page1' }, { path:'page1', component:'PageComponent1' }, { path:'page2', component:'PageComponent2' } ]