angular路由
2020-04-03 本文已影响0人
fk1102
1.四种路由形式
1.{path:'a',component:'AComponent'}
2.{path:'a/:id',component:'AComponent'}
3.{path:'a',component:'AComponent',data:{title:'xxx'}}
4.{path:'',redirect:'a',pathMatch:'full'}
5.{path:'**',component:'BComponent'}
路由的时候是有顺序的,所以写的时候也需要有顺序的

2.注意点

RouterModule.forRoot(xxx);

4.使用router-outlet的时候,并不需要把那个componet加了module里去
5.routerLinkActive是啥
6.命令
ng generate component a/a/b --flat
1.如果这些文件都不在,则会创建;存在,就在下面创建
2.添加--flat的话,b会直接转化为a/a/b.component.ts;不添加的话,会创建a/a/b/b.component
ng generate module a/a/b --flat --routing --module app
1.--flat和之前一样
2.不加--routing,只创建b.module.ts;加了的话,会添加b-routing.module.ts
3.--module app一般同时使用,表明创建好的BModule会添加到AppModule中去