2

当通过根 url (localhost:4200/) 执行后端调用时,Mirage 确实匹配定义的路由,但是当我们在子页面 ea:localhost:4200/process 上执行后端调用时,它将不起作用。在调试 mirage 代码时,它会尝试通过在要匹配的 url 前加上“进程”来进行匹配。因此,如果 BE 调用是“api/portal/affiliates/”,它将尝试匹配“process/api/portal/affiliates/”,但由于不存在匹配路径而失败。任何想法如何解决这个问题。

我们在 Angular 9 中使用 mirage.js。 roue mirage.js 配置:

    routes() {
      this.passthrough();

      this.namespace = '/api/portal;
      this.get('affiliates', (schema, request) => {
        return schema.db.affiliates;
      })
}
4

1 回答 1

0

我正在将 mirage 集成到 Angular-9 中。

我面临着同样的问题。每次在任何带有某些路由的 URL 上刷新页面时,都会引发 mirage 找不到路由的错误。

问题不在于海市蜃楼。问题是我如何调用 API。

而不是做

this.http.get('api/portal')

尝试做如下

this.http.get('/api/portal')

在调用 API 时添加/(正斜杠)。这解决了我的问题。让我知道它是否仍然无法解决您的问题。

于 2020-08-12T13:45:10.533 回答