我有两条我想要匹配的路线,但它们相互冲突。我有path: ":page"
的通用路由,但我有另一条特定的路由path: "id_token"
。理想情况下,路由器会先检查path: "id_token"
是否匹配,然后再恢复为path: ":page"
。
export const ROUTES: Route[] = [
// If this route is a match then use this config
{
path: "id_token",
pathMatch: "prefix",
redirectTo: ":page/d",
},
// Otherwise use this config
{
path: ":page",
component: "PageComponent",
}
];
答案 0 :(得分:1)
您可以将CanActive用于此
@Injectable()
class MyCanActivate implements CanActivate {
constructor() {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean>|Promise<boolean>|boolean {
return true/false; //to active/deactive your route
}
}
然后为你的路线:
export const ROUTES: Route[] = [
// If this route is a match then use this config
{
path: "id_token",
pathMatch: "prefix",
redirectTo: ":page/d",
canActivate: [MyCanActivate]
},
// Otherwise use this config
{
path: ":page",
component: "PageComponent",
}
];