【问题标题】:On Browser reload Angular js 2 nested routes component not loading在浏览器重新加载Angular js 2嵌套路由组件未加载
【发布时间】:2016-04-13 16:48:49
【问题描述】:

我有一个在父组件下创建子路由的 routeconfig,我注意到当我使用(通过单击将 routelink 设置为子路由的 href 标记)路由链接来访问嵌套路由时,一切都会发生,但是当我在子路由上刷新浏览器或直接在浏览器中输入子路由链接时,它无法加载子组件,即仅加载父组件。

有问题的网址 - localhost:3000/#/dashboard/reservation

我的路线配置如下

主应用组件路由到父组件(仪表板)

@RouteConfig([
  ...
  { path: '/dashboard/...', name: 'Dashboard', component: Dashboard}, 
  ...
])

Dashboard component creates child route
@RouteConfig([
  { path: '/reservation', name: 'Reservation', component: Reservation , useAsDefault: true},
]);

【问题讨论】:

  • 你在哪里添加ROUTER_PROVIDERS?我认为您需要提供更多信息(更多代码),否则很难诊断。任何具体的错误信息?
  • 我认为问题是我使用的自定义路由出口指令,它试图在浏览器刷新时重新验证用户,并以某种方式阻止子组件加载。如果我使用默认路由出口,则不会出现此问题。
  • 我遇到了同样的问题,因为控制台中出现错误“ReferenceError: System is not defined”。运气好吗?
  • 同样的错误......

标签: angular angular2-routing


【解决方案1】:

我遇到了同样的问题,但我通过在 <head>index.html 中使用此代码解决了问题。这是 APP_BASE_HREF 的错误

<base href="/">
<!-- Set the base href -->
<script>document.write('<base href="'+ document.location +'"/>');</script>

【讨论】:

    猜你喜欢
    • 2018-03-20
    • 2015-10-03
    • 2023-03-23
    • 1970-01-01
    • 2019-12-06
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多