vue.js - Quasar 框架:引导时重定向不起作用
问题描述
如果未定义 socketio 的连接数据,我正在尝试重定向到设置页面。但我不能让它按照 Quasar 文档在这里工作
这是启动文件:
/*eslint-disable no-unused-vars*/
export default ({ Vue, redirect, urlPath }) => {
const hostIp = process.env.HOST_IP
? process.env.HOST_IP
: LocalStorage.getItem("hostIp") || null;
const hostPort = process.env.HOST_PORT
? process.env.HOST_PORT
: LocalStorage.getItem("hostPort") || 3002;
if (!urlPath.startsWith("/endpointsetup") && (!hostIp || !hostPort)) {
redirect({ path: "/endpointsetup" });
return;
}
Vue.prototype.$socket = io.connect(`http://${hostIp}:${hostPort}`);
};
和路由器:
//router/index.js
export default function (/* { store, ssrContext } */) {
const Router = new VueRouter({
scrollBehavior: () => ({ x: 0, y: 0 }),
routes,
mode: process.env.VUE_ROUTER_MODE,
base: process.env.VUE_ROUTER_BASE
})
return Router
}
//router/routes.js
const routes = [
{
path: '/',
component: () => import('layouts/MainLayout.vue'),
children: [
{ path: '', component: () => import('pages/Index.vue') },
{ path: '/schedules', name: 'Schedules', component: () => import('pages/Schedules') },
{ path: '/settings', name: 'Settings', component: () => import('pages/Settings') },
{ path: '/endpointsetup', name: 'EndpointSetup', component: () => import('pages/EndpointSetup') },
{ path: '/login', name: 'Login', component: () => import('pages/Login')}
]
},
{
path: '*',
component: () => import('pages/Error404.vue')
}
]
export default routes
似乎是试图重定向到 0.0.0.0:8080/endpointsetup 但是,如果我评论重定向并手动导航到该页面,它会成功打开:0.0.0.0:8080/#/endpointsetup
解决方案
推荐阅读
- flutter - 无效的参数:找不到可执行文件的位置。:颤动
- swift - 如何确定 .background() 需要指定颜色,然后输入 .colorName (作为文本修饰符)
- batch-file - 批量过滤文件中的匹配行以输出
- javascript - Ajax:为什么 post 请求会被触发两次?
- algorithm - 解决迷宫的最佳算法?
- javascript - (this:ClassName) 参数在 TypeScript 中是什么意思?
- java - 在java中更改嵌套映射中的内部值类型的最简单方法是什么?
- c# - Unity 脚本导入设置定义默认变量值
- apache-spark - 启用 SSL 后,Spark UI 不使用 HTTPS,而是通过 HTTP 转发到端口 0
- jquery - .append()、选择列表和 Chrome 81 存在问题