Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular Routes介绍 #55

Open
deepthan opened this issue Jun 16, 2020 · 0 comments
Open

Angular Routes介绍 #55

deepthan opened this issue Jun 16, 2020 · 0 comments

Comments

@deepthan
Copy link
Owner

什么是 Routes ?

它是一组路由的配置信息,均包含以下配置:

export declare type Routes = Route[];

export interface Route {
    path?: string;
    pathMatch?: string;
    matcher?: UrlMatcher;
    component?: Type<any>;
    redirectTo?: string;
    outlet?: string;
    canActivate?: any[];
    canActivateChild?: any[];
    canDeactivate?: any[];
    canLoad?: any[];
    data?: Data;
    resolve?: ResolveData;
    children?: Routes;
    loadChildren?: LoadChildren;
    runGuardsAndResolvers?: RunGuardsAndResolvers;
}
  • path: 路径
path: 'signin'

它是一个用Angular路由器去匹配url对应关键词的字符串。
path为 signin 那么对应的 url 是.../signin

  • pathMatch: 路径匹配规则
pathMatch : 'prefix' // 默认的
pathMatch : 'full' 

prefix(前缀)是默认的,会去匹配url是否含有path字段,如果有则进行重定向。
full(完整的),加上他会看path和路径是否完全一致,一致的话则重定向。

  • matcher: 定义路径匹配的自定义策略,并取代路径和路径匹配规则
  • component: 需要渲染的组件
  • redirectTo: 重定向到的路由地址
  • outlet: 一个路由对应多个组件
// 路由
{ path: 'news', outlet: 'outlet1', component: demo1Component },
{ path: 'news', outlet: 'outlet2', component: demo2Component },
//组件里面
<router-outlet name="outlet1"></router-outlet>
<router-outlet name="outlet2"></router-outlet>
  • canActivate: 控制是否允许进入路由
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant