Я в сложном положении. Я работаю над приложением Aurelia, у которого есть несколько маршрутов, которые устанавливаются на основе простого GET-запроса к API.
Что работает (нет запроса API или задержка шага configureRouter
):
export class MyClass{
static inject = [some stuff here];
configureRouter(config, router) {
this.router = router;
let routes = [
{ route: '', redirect: 'landing' },
{ route: 'landing', name: 'landing', moduleId: PLATFORM.moduleName('components/landing'), title: 'landing' },
{ route: 'pageA', name: 'pageA', moduleId: PLATFORM.moduleName('components/pageA'), title: 'Page A' },
{ route: 'pageB', name: 'pageB', moduleId: PLATFORM.moduleName('components/pageB'), title: 'Page B' }];
config.map(routes);
}
Что не работает:
export class MyClass{
static inject = [some stuff here];
configureRouter(config, router) {
this.router = router;
let routes = [
{ route: '', redirect: 'landing' },
{ route: 'landing', name: 'landing', moduleId: PLATFORM.moduleName('components/landing'), title: 'landing' }];
this.routesRepo.get().then((data) => {
// data is array representing
// [{ route: 'pageA', name: 'pageA', moduleId: PLATFORM.moduleName('components/pageA'), title: 'Page A' },
// { route: 'pageB', name: 'pageB', moduleId: PLATFORM.moduleName('components/pageB'), title: 'Page B' }];
routes.concat(data);
config.map(routes);
}
});
И что не работает (простой тайм-аут):
export class MyClass{
static inject = [some stuff here];
configureRouter(config, router) {
this.router = router;
let routes = [];
setTimeOut(() => {
routes.concat(
[ { route: '', redirect: 'landing' },
{ route: 'landing', name: 'landing', moduleId: PLATFORM.moduleName('components/landing'), title: 'landing' },
{ route: 'pageA', name: 'pageA', moduleId: PLATFORM.moduleName('components/pageA'), title: 'Page A' },
{ route: 'pageB', name: 'pageB', moduleId: PLATFORM.moduleName('components/pageB'), title: 'Page B' } ]);
config.map(routes);
}, 1);
}
Почему добавляется config.map(routes)
в пределах обещать все испортить? Как один go об этом тогда? Массив routes
имеет все необходимое и правильно настроен, прежде чем достигнет config.map(routes)
. Все, что я сейчас получаю, это моя пользовательская страница 404.
Спасибо!