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