【发布时间】:2018-09-10 09:08:21
【问题描述】:
我在为我的项目实现子路由时遇到错误。我在 GitHub 和其他网站上没有找到任何帮助。
ERROR 错误:未捕获(承诺中):SecurityError:执行失败 'History' 上的 'pushState':带有 URL 的历史状态对象 'http://%28routes%29/' 无法在具有来源的文档中创建 'http://localhost:4200' 和 URL 'http://localhost:4200/'。错误: 无法在“历史”上执行“pushState”:历史状态对象 无法在具有 URL 'http://%28routes%29/' 的文档中创建 来源 'http://localhost:4200' 和 URL 'http://localhost:4200/'。
【问题讨论】:
-
您好,您能告诉我们您是如何配置路线的吗?
-
如果您在问题中添加代码实现,它将帮助我们找到您的答案
-
尝试使用基于哈希的路由策略导入 [RouterModule.forRoot(routes, {useHash: true})]
-
const appRoutes: Routes = [ { path: '', component: HomeComponent, canActivate: [AuthGuard], children: [ {path: '', component: CutoffValidationComponent}, {path: 'CutoffValidation' ,组件:CutoffValidationComponent},{路径:'routes',组件:RoutesComponent},{路径:'cutoffs',组件:CutoffsComponent}]},{路径:'登录',组件:LoginComponent },{路径:'** ', 重定向到:'' } ]; export const routing = RouterModule.forRoot(appRoutes, { enableTracing: false });