admin管理员组文章数量:1406950
I am trying to take out router configuration from app.js
file and put it in a separate file (app.router.js
). This is probably an easy thing to do but I don't know how to do it.
Current app.js
file looks like this:
import {Router} from 'aurelia-router';
export class App {
static inject() { return [Router]; };
constructor(router) {
this.router = router;
// router - put this part in a separate file
this.router.configure(config => {
config.title = 'demo';
config.options.pushState = true;
config.map([
// home routes
{ route: ['','home'], moduleId: './home/home', nav: true, title:'Home' },
// User routes
{ route: ['user/register'], moduleId: './user/register', nav: true, title:'User Registration'}
]);
});
}
}
Once the configuration part is in a separate file, I believe I have call it like this in app.js
:
this.router.configure(myRouterConfig);
Please let me know how to do it with code example.
I am trying to take out router configuration from app.js
file and put it in a separate file (app.router.js
). This is probably an easy thing to do but I don't know how to do it.
Current app.js
file looks like this:
import {Router} from 'aurelia-router';
export class App {
static inject() { return [Router]; };
constructor(router) {
this.router = router;
// router - put this part in a separate file
this.router.configure(config => {
config.title = 'demo';
config.options.pushState = true;
config.map([
// home routes
{ route: ['','home'], moduleId: './home/home', nav: true, title:'Home' },
// User routes
{ route: ['user/register'], moduleId: './user/register', nav: true, title:'User Registration'}
]);
});
}
}
Once the configuration part is in a separate file, I believe I have call it like this in app.js
:
this.router.configure(myRouterConfig);
Please let me know how to do it with code example.
Share Improve this question edited Mar 25, 2015 at 22:28 Jordan Running 106k18 gold badges188 silver badges187 bronze badges asked Mar 25, 2015 at 22:18 Golden moleGolden mole 5036 silver badges14 bronze badges1 Answer
Reset to default 9The solution is easier to understand when you realize that the argument you pass to this.router.configure
is just a function. To put your router configuration in a separate file, just have that file export a function that takes one argument (config
).
// app.router.js
export default function (config) {
config.title = 'demo';
config.options.pushState = true;
config.map([
// home routes
{ route: ['','home'], moduleId: './home/home', nav: true, title:'Home' },
// User routes
{ route: ['user/register'], moduleId: './user/register', nav: true, title:'User Registration'}
]);
}
Then, in app.js
:
import appRouter from 'app.router';
// ...then...
this.router.configure(appRouter);
You can, of course, name appRouter
anything you want.
本文标签: javascriptPut router configuration in a separate file in AureliaStack Overflow
版权声明:本文标题:javascript - Put router configuration in a separate file in Aurelia - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744937285a2633265.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论