vue.js - “通过导航守卫从 {route} 重定向到 {another route}。” 在进行第二次重定向后
问题描述
我在使用我的代码进行重定向时遇到问题。
我有这样的事情:
store/auth.js:
async login(credentials) {
const user = await api.post(credentials);
if (user.role === 'someRole') {
router.push({name: 'warehouses'});
}
}
我将用户重定向到仓库,这很好,但是当我尝试再次将用户重定向到他们自己的仓库时:
warehouses.vue
async beforeRouteEnter(to, from, next) {
const user = store.getters.getUser;
const warehouses = await api.get('warehouses');
const userWarehouse = getWarehouseOwner(user, warehouses);
if (userWarehouse) {
next({name: 'warehouse', params: {id: userWareHouse }})';
}
}
然后我收到一个错误:
Uncaught (in promise) Error: Navigation cancelled from "/login" to "/warehouses" with a new navigation.
我阅读了有关此特定错误的信息,看起来不受支持。我怎样才能绕过这个错误?有没有办法可以执行第二次重定向?
解决方案
推荐阅读
- python - 在排序一个列表期间将不同列表中的相关元素保持在一起
- c# - 如何对通用列表对象进行排序
- javascript - 向和从 js 服务器发送数据的基本方法?
- json - 使用 Pyspark 处理 JSON 结构
- amazon-web-services - 为什么角色假设应该在 lambda 内部完成?
- html - 如何将数值绑定到 CSS 以创建时间线?
- docker - 如何为 docker compose 环境变量设置运行时变量
- javascript - 仅在 Javascript 中具有不同段落的动态 Div
- tsql - 表格模型中的测量列未在浏览器中显示正确的值
- javascript - 调用此函数时如何获取返回值?