【问题标题】:Getting the error "Unable find module with ID" with Aurelia Router使用 Aurelia 路由器获取错误“无法找到具有 ID 的模块”
【发布时间】:2017-09-11 14:25:34
【问题描述】:

我正在尝试使用 aurelia-router 在 Aurelia 中配置路由,但它会抛出一个错误,即找不到我的路由的 moduleId(route to file)。

我在两个文件 router.js 和 app.js 中配置我的路由,路由器文件只包含一个包含所有路由的数组。 app 文件是我项目的主文件。

项目结构:

Router.js:

export default [
  { route: ['', '/', 'home'], name: 'home', title: 'Inicio', layoutView: 'components/common/layout/layout.html', moduleId: 'components/home/home' }
]

App.js

import routes from 'router'
import {RouterConfiguration, Router} from 'aurelia-router';

export class App {

  configureRouter(config, router){
    config.options.root = '/';
    config.title = 'La Tatuadora';
    this.router = router;
    config.map(routes);
  }
}

错误

【问题讨论】:

  • home.htmlhome.js的内容是什么?
  • 我已经找到了解决方案,我使用 Webpack 作为打包器,webpack 需要一个解析器来查找模块,Aurelia 提供了PLATFORM.moduleName("moduleId") 来解析模块,它带有aurelia-pal 包。在使用中它看起来像这样:moduleId: PLATFORM.moduleName("components/home/home").
  • 我也经常想念这个。最好回答您自己的问题并提及PLATFORM.moduleName()
  • @DanyNsg 啊,好地方。你能自己回答这个问题来帮助别人吗?

标签: javascript aurelia


【解决方案1】:

Aurelia 提供PLATFORM.moduleName("moduleId") 来解析模块,它带有aurelia-pal 包。

在使用中是这样的:

{ moduleId: PLATFORM.moduleName("components/home/home") }

【讨论】:

  • 非常有用的答案,让我省了很多麻烦。谢谢。
猜你喜欢
  • 1970-01-01
  • 2017-09-25
  • 1970-01-01
  • 2018-01-20
  • 2020-08-27
  • 1970-01-01
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多