【问题标题】:Is there any way that I can construct the cross folder route using route-href in Aurelia 1.1.2?有什么方法可以在 Aurelia 1.1.2 中使用 route-href 构建跨文件夹路由?
【发布时间】:2017-04-19 11:38:17
【问题描述】:

目前,我的文件夹结构如下:

D:.
|   app.html
|   app.js
+---calendars
|       calendar-router.html
|       calendar-router.js
|       details.html
|       details.js
|
+---organizations
|       service.js
|
\---users
        details.html
        details.js
        users-router.html
        users-router.js

我想在 calendars/details.html 文件中创建一个指向 users/details.html 文件的链接 href。

<a route-href="route: userDetails; params.bind: { id: calendar.owner.id }">details</a>

我的 users-router.js 有这个条目。

 { route: 'details/:id', name: 'userDetails', moduleId: './details', title: 'User details', href: 'details/:id' }

但不知何故,我无法这样做,并收到错误 [route-href] 错误:找不到名为“userDetails”的路由。检查路由配置中是否指定了name: 'userDetails'。

我尝试在 calendar/details.js 中同时注入 app.js 和 users-router.js 路由器,我可以查看 AppRouter 已填充,但 UsersRouter 未填充。

有什么办法可以做到吗?

【问题讨论】:

  • route-href 中的路由参数应该是字符串。您是否已经尝试过,或者您只是在问题中输入错误?
  • @janmvtrinidad,route-href 的整个值是一个字符串。
  • 当您尝试从日历导航到用户/详细信息时,您能否发布您的 app.js routerConfiguration.map 以及 url 浏览器中的值?
  • @janmvtrinidad 在这里。 app.js config.map([ { route: 'users', name: 'users', moduleId: './users/users-router', nav: true, title: 'Users' }, { route: 'calendars', name: 'calendars', moduleId: './calendars/calendar-router', nav: true, title: 'Calendars' } ]); 地址栏中的值为 localhost:9000/#/calendars/details/58f27138a1f59e55e8ca93c2
  • 问题出在 calendar/details.html 页面上,它无法创建到 user/details.html 的路由。

标签: aurelia


【解决方案1】:

您获得未知路由名称的原因是 Aurelia 不会急切地加载子路由器。

在您的用户路由被导航到之前,您的 app.js 中的 AppRouter 不会配置子路由器。

最简单的解决方案是在 app.js 中包含路由。然后您现有的 route-href 将起作用。

您可以在 github 上查看此问题以获取其他解决方案。 https://github.com/aurelia/router/issues/90

【讨论】:

    猜你喜欢
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多