使用Angular2开发,常会遇到路由重定向的应用场景。

  路由重定向的配置办法是这样的:

{path:'要定向的路径', redirectTo:'要定向到的目标路由'}

  比如某组件有个路由插件,并且一进入该组件就想要路由插件加载出内容,我们的路由配置可能这么写:

routes: Routes = [
	{
		path:'',
		component:'ParentComponent',
		children:[
			{ path:'', redirectTo: 'page1' },//定向
			{ path:'page1', component:'PageComponent1' },
			{ path:'page2', component:'PageComponent2' }
		]           
	}   
]

  如果是兄弟路由之间的定向,则类似这样:

routes: Routes = [
	{ path:'', redirectTo: 'page1' },
	{ path:'page1', component:'PageComponent1' },
	{ path:'page2', component:'PageComponent2' }
]

  

相关文章:

  • 2021-12-02
  • 2022-12-23
  • 2021-05-01
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2022-02-15
  • 2022-02-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2021-09-13
  • 2021-07-02
相关资源
相似解决方案