微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular: Route 参数详解

使用场景

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;

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐