Const路线以红色突出显示并输出以下错误:
Type "({path: string; component: Route [];} | {path: string;
component: Route []; canActivate: (typeof ..." can not be assigned for
type "Route []".
Type "{path: string; component: Route [];} | {path: string; component:
Route []; canActivate: (typeof ..." can not be assigned to the "Route"
type.
The "{path: string; component: Route [];}" type can not be assigned to
the "Route" type.
The property types of the "component" are incompatible.
The "Route []" type can not be assigned for type "type <any>".
The "apply" property is not present in the type "Route []".
依旧......
我该如何解决这个问题?
import { Routes } from '@angular/router';
import { SignInRoutes } from '../layout/sign-in/index';
import { LayoutRoutes } from '../layout/index';
import { SignInComponent } from '../layout/sign-in/sign-in.component';
import { AuthGuard } from '../shared/guards/auth.guard';
export const routes: Routes = [
{ path: 'sign_in', component: SignInRoutes },
{ path: 'layout', component: LayoutRoutes, canActivate: [AuthGuard] },
{ path: '**', component: SignInComponent }
];
答案 0 :(得分:0)
看起来您正在将路由分配给不允许的组件属性。如果您尝试实现嵌套路由,则应使用children属性。请参阅教程了解更多info
答案 1 :(得分:0)
我附上了一个例子。
const recipesRoutes : Routes = [
{ path: 'recipes', component: RecipesComponent, children: [
{ path: '', component: RecipeStartComponent },
{ path: 'new', component: RecipeEditComponent, canActivate: [AuthGuard] },
{ path: ':id', component: RecipeDetailComponent },
{ path: ':id/edit', component: RecipeEditComponent, canActivate: [AuthGuard] },
] },
];
希望这会有所帮助!!