首页 > 解决方案 > 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

标签: vue.jsquasar-framework

解决方案


推荐阅读