我有以下代码,基本上是 app.js 中的主路由器和仪表板 js 中的子路由器。每当我转到根 url '/' 时,我都会在浏览器控制台中收到警告。我不明白这里的问题是什么,重定向甚至可以正常工作并且显示所有内容,但我仍然收到这个巨大的警告,告诉我出了点问题。我错过了什么?任何帮助表示赞赏。
浏览器控制台警告
Warning: a promise was rejected with a non-error: [object Object]
at _buildNavigationPlan (http://localhost:9000/scripts/vendor-bundle.js:14942:22)
at BuildNavigationPlanStep.run (http://localhost:9000/scripts/vendor-bundle.js:14922:14)
at next (http://localhost:9000/scripts/vendor-bundle.js:14488:20)
at Pipeline.run (http://localhost:9000/scripts/vendor-bundle.js:14501:14)
at http://localhost:9000/scripts/vendor-bundle.js:16050:25
From previous event:
at AppRouter._dequeueInstruction (http://localhost:9000/scripts/vendor-bundle.js:16023:32)
at http://localhost:9000/scripts/vendor-bundle.js:16014:17
From previous event:
at AppRouter._queueInstruction (http://localhost:9000/scripts/vendor-bundle.js:16011:14)
at http://localhost:9000/scripts/vendor-bundle.js:15945:23
From previous event:
at AppRouter.loadUrl (http://localhost:9000/scripts/vendor-bundle.js:15944:53)
at BrowserHistory._loadUrl (http://localhost:9000/scripts/vendor-bundle.js:11474:55)
at BrowserHistory._checkUrl (http://localhost:9000/scripts/vendor-bundle.js:11467:14)
应用程序.js
export class App {
configureRouter(config, router) {
this.router = router;
config.map([
{ route: '', redirect: 'dashboard' },
{ route: 'dashboard', name: 'dashboard', title: 'Dashboard', moduleId: 'views/dashboard', auth: true }
]);
}
}
应用.html
<template>
<require from="material-design-lite/material.css"></require>
<router-view></router-view>
</template>
仪表板.js
export class Dashboard {
configureRouter(config, router) {
this.router = router;
config.map([
{ route: 'fairs', name: 'fairs', title: 'Messen', moduleId: 'views/fairs', nav: true },
{ route: '', redirect: 'fairs' }
]);
}
attached() {
componentHandler.upgradeAllRegistered();
}
}
仪表板.html
<template>
<router-view></router-view>
</template>
最佳答案
我也在研究同样的事情,我认为它是故意这样写的。导致警告的代码来自组成 AppRouter 对象的一长串 promise 。
由于重定向步骤由该链中的不同方法处理,因此当它到达 BuildNavigationPlanStep.run(...) 时步骤,该特定 promise 被拒绝,因为它已被上游处理(RedirectToRoute.navigate(...))。这是我阅读堆栈跟踪后的最佳猜测。
我假设警告正在从 Bluebird promise api 打印到控制台,但我不是 100% 确定。
关于javascript - 带有子路由器的 Aurelia-Router 显示警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39593463/