【发布时间】:2019-01-24 05:44:24
【问题描述】:
我正在根据运行良好的条件设置“”路径并设置到“”路径的路径。我在我的开发服务器上工作正常。但是当我构建项目并在生产服务器上运行它时,它给了我这个错误。
未捕获的错误:路由“ ”的配置无效。必须提供以下之一:component、redirectTo、children 或 loadChildren
这是我的 app-routing.module.ts
const fallback: Route = {
path: '**',
component: NotFoundComponent
}
var home: Route = {};
const hostName = window.location.host;
console.log('hostName: ', hostName);
var workspaceName = hostName.split('.')[0];
console.log('workspaceName: ', workspaceName);
if (workspaceName === 'peprix' || workspaceName === 'www') {
console.log("if");
let homeRoute: Route = {
path: '', component: MainComponent
}
home = homeRoute;
} else {
console.log("else");
let homeRoute: Route = {
path: '', canActivate: [SessionGuard], data: { workspaceName: workspaceName }, resolve: { workspaceId: SigninService }, component: SigninNextComponent
}
home = homeRoute;
}
const routes: Routes = [
home,
{ path: 'signin', canActivate: [SessionGuard], component: SigninComponent, data: { workspaceName: workspaceName } },
{ path: 'create-workspace', canActivate: [SessionGuard], component: CreateWorkspaceComponent },
{ path: 'projects', canActivate: [ProjectGuard], component: ProjectComponent },
{ path: 'password-reset', component: PasswordResetComponent },
{ path: 'new-password', component: NewPasswordComponent },
fallback
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: [
ProjectDetailsService,
SigninService
]
})
export class AppRoutingModule { }
P.S:我已经导入了所有组件和依赖项,所以这里没有问题。
【问题讨论】:
-
var home: Route = {};home 不能为空[此评论可能对将来的某人有所帮助]
标签: angular angular-routing angular-router