使用场景
const routes: Routes = []; // 这里
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
详情
export declare type Routes = Route[];
export declare type UrlMatcher = (
segments: UrlSegment[],
group: UrlSegmentGroup,
route: Route) => UrlMatchResult | null;
export declare type LoadChildren = () => Type<any> |
NgModuleFactory<any> |
Observable<Type<any>> |
Promise<NgModuleFactory<any> | Type<any> | any>;
export declare interface Route {
// 这个就不解释了
path?: string;
// 匹配规则,默认值是 prefix
pathMatch?: 'prefix' | 'full';
// path 和 matcher,只能二选一. matcher的用法后面详细写
matcher?: UrlMatcher;
component?: Type<any>;
// Note that no further redirects are evaluated after an absolute redirect
redirectTo?: string;
// outlet对象的名字
outlet?: string;
canActivate?: any[];
canActivateChild?: any[];
canDeactivate?: any[];
canLoad?: any[];
// 通过ActivatedRoute可以获取这个data数据
data?: Data;
// ???
resolve?: ResolveData;
children?: Routes;
/* 懒加载的子路由,常用 :
loadChildren: () => import('./pages/home/home.module')
.then(mod => mod.HomeModule)*/
loadChildren?: LoadChildren;
// ???
runGuardsAndResolvers?: RunGuardsAndResolvers;
}