当通过根 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;
})
}