javascript - 带有子路由器的 Aurelia-Router 显示警告

标签 javascript promise aurelia

我有以下代码,基本上是 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/

相关文章:

javascript - 如何关闭 jQuery 工具提示

javascript - 如何在ajax成功中中断执行并显示错误?

javascript - Coffeescript,我将如何编写这个排队函数示例,尤其是循环?

javascript - 在 sagas 中使用 race 的优势

reactjs - React Hook 异步等待如何保持渲染 promise

javascript - oidc-client CheckSessionIFrame 正确触发一次,然后每隔一段时间就会失败

javascript 代码运行顺序

scala - promise 有缺陷吗?

javascript - 如何在 Aurelia.JS 中显示当前事件页面标题

aurelia - 在 Aurelia 中测试具有可绑定(bind)字段的类