【问题标题】:Angular universal starter: Cannot match any routes. URL Segment: 'robots.txt'Angular 通用启动器:无法匹配任何路线。 URL 段:“robots.txt”
【发布时间】:2018-11-28 13:18:05
【问题描述】:

我下载了这个 Angular 通用启动器 https://github.com/angular/universal-starter

从 package.json 安装所有依赖项并尝试启动项目。 首先我运行“ng build”命令,然后在下一个命令“npm run build:ssr && npm run serve:ssr”

一切正常,但有时我会在终端收到下一条消息:

ERROR { Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'robots.txt'
Error: Cannot match any routes. URL Segment: 'robots.txt'
    at ApplyRedirects.noMatchError (D:\universal-starter-master\universal-starter-master\node_modules\@angular\router\bundles\router.umd.js:2557:20)
    at CatchSubscriber.selector (D:\universal-starter-master\universal-starter-master\node_modules\@angular\router\bundles\router.umd.js:2538:33)
    at CatchSubscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\operators\catchError.js:48:31)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at TapSubscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\operators\tap.js:75:26)
    at resolvePromise (D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:814:31)
    at resolvePromise (D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:771:17)
    at D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:873:17
    at ZoneDelegate.invokeTask (D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:421:31)
    at Object.onInvokeTask (D:\universal-starter-master\universal-starter-master\node_modules\@angular\core\bundles\core.umd.js:16177:37)
    at ZoneDelegate.invokeTask (D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:420:36)
    at Zone.runTask (D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:188:47)
    at drainMicroTaskQueue (D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:595:35)
    at ZoneTask.invokeTask (D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:500:21)
    at ZoneTask.invoke (D:\universal-starter-master\universal-starter-master\node_modules\zone.js\dist\zone-node.js:485:48)
  rejection: Error: Cannot match any routes. URL Segment: 'robots.txt'
    at ApplyRedirects.noMatchError (D:\universal-starter-master\universal-starter-master\node_modules\@angular\router\bundles\router.umd.js:2557:20)
    at CatchSubscriber.selector (D:\universal-starter-master\universal-starter-master\node_modules\@angular\router\bundles\router.umd.js:2538:33)
    at CatchSubscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\operators\catchError.js:48:31)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at TapSubscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\operators\tap.js:75:26),
  promise:
   ZoneAwarePromise {
     __zone_symbol__state: 0,
     __zone_symbol__value: Error: Cannot match any routes. URL Segment: 'robots.txt'
    at ApplyRedirects.noMatchError (D:\universal-starter-master\universal-starter-master\node_modules\@angular\router\bundles\router.umd.js:2557:20)
    at CatchSubscriber.selector (D:\universal-starter-master\universal-starter-master\node_modules\@angular\router\bundles\router.umd.js:2538:33)
    at CatchSubscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\operators\catchError.js:48:31)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at TapSubscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\operators\tap.js:75:26) },
  zone:
   Zone {
     _properties: { isAngularZone: true },
     _parent:
      Zone {
        _properties: {},
        _parent: null,
        _name: '<root>',
        _zoneDelegate: [Object] },
     _name: 'angular',
     _zoneDelegate:
      ZoneDelegate {
        _taskCounts: [Object],
        zone: [Circular],
        _parentDelegate: [Object],
        _forkZS: null,
        _forkDlgt: null,
        _forkCurrZone: [Object],
        _interceptZS: null,
        _interceptDlgt: null,
        _interceptCurrZone: [Object],
        _invokeZS: [Object],
        _invokeDlgt: [Object],
        _invokeCurrZone: [Circular],
        _handleErrorZS: [Object],
        _handleErrorDlgt: [Object],
        _handleErrorCurrZone: [Circular],
        _scheduleTaskZS: [Object],
        _scheduleTaskDlgt: [Object],
        _scheduleTaskCurrZone: [Circular],
        _invokeTaskZS: [Object],
        _invokeTaskDlgt: [Object],
        _invokeTaskCurrZone: [Circular],
        _cancelTaskZS: [Object],
        _cancelTaskDlgt: [Object],
        _cancelTaskCurrZone: [Circular],
        _hasTaskZS: [Object],
        _hasTaskDlgt: [Object],
        _hasTaskDlgtOwner: [Circular],
        _hasTaskCurrZone: [Circular] } },
  task:
   ZoneTask {
     _zone:
      Zone {
        _properties: [Object],
        _parent: [Object],
        _name: 'angular',
        _zoneDelegate: [Object] },
     runCount: 0,
     _zoneDelegates: null,
     _state: 'notScheduled',
     type: 'microTask',
     source: 'Promise.then',
     data:
      ZoneAwarePromise {
        __zone_symbol__state: 0,
        __zone_symbol__value: Error: Cannot match any routes. URL Segment: 'robots.txt'
    at ApplyRedirects.noMatchError (D:\universal-starter-master\universal-starter-master\node_modules\@angular\router\bundles\router.umd.js:2557:20)
    at CatchSubscriber.selector (D:\universal-starter-master\universal-starter-master\node_modules\@angular\router\bundles\router.umd.js:2538:33)
    at CatchSubscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\operators\catchError.js:48:31)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at MapSubscriber.Subscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:93:26)
    at MapSubscriber.Subscriber.error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\Subscriber.js:73:18)
    at TapSubscriber._error (D:\universal-starter-master\universal-starter-master\node_modules\rxjs\internal\operators\tap.js:75:26) },
     scheduleFn: undefined,
     cancelFn: null,
     callback: [Function],
     invoke: [Function] } }

我该如何解决这个问题? 为了捕捉这条消息,我多次点击浏览器中的刷新按钮。

【问题讨论】:

  • 因为您的代码中缺少 robots.txt 文件
  • robots.txt文件应该在哪个代码文件中?
  • 这需要检查代码,通过看起来似乎问题是这样的
  • 我试图找到 robots.txt,但在所有项目中都没有提到“机器人”。
  • 如果我将robot.txt文件添加到dist文件夹,就不会出现这个错误了。

标签: angular angular-cli robots.txt angular-universal


【解决方案1】:

这是solution 的作品。但是我仍然不明白为什么开发人员没有在项目中包含 robots.txt 这么简单。可能有什么原因?

【讨论】:

    猜你喜欢
    • 2020-11-06
    • 1970-01-01
    • 2023-01-09
    • 2018-10-03
    • 2018-09-29
    • 2020-06-22
    • 2017-09-25
    • 2019-05-01
    • 1970-01-01
    相关资源
    最近更新 更多