Jump between vue router non-components

the project function to be implemented

I need to make a judgment before I log in to the gateway
I encapsulate an axios that requests the backend network every time and returns a status code
when the return status is: login timeout, I router jump instead of window.location="/login"

related codes

import Vue from "vue"
import router from "vue-router"
import axios from "axios";

Vue.prototype.$ajax = axios
//axios
export default function(url,data={}){
    ......
    if(){
        ...router...//
        /*router.push("")*/
    }
}
Apr.12,2021

here router is a Router dependency that is not import Router from 'vue-router' .
it is actually a router object exported after routing for unified management.

// router.js
import Router from "vue-router";
import Home from 'Home.vue'
Vue.use(Router);

// router
export default new Router({
    routes: [
        {
          path: "/",
          name: "home",
          component: Home,
          children: [
            {
              path: "/a",
              name: "a",
              component: A
            }
        ]
})

on the page you need, introduce such an object instance, and then use the router.push method

// js
// router.js
import router from 'router.js'
...
...
func(){
...
    router.push('/');
...    
}


whether the encapsulated file is in a separate js file, you may need to import router to use router.push

import {router} from '@/router/index'

router/index.js

import Vue from 'vue'
import iView from 'iview'
import VueRouter from 'vue-router'
import Cookies from 'js-cookie'
import { routers } from './router'

Vue.use(VueRouter)

const RouterConfig = {
  mode: 'history',
  routes: routers
}

export const router = new VueRouter(RouterConfig)

what you need is the object after new VueRouter.


const router = new Router({
  mode: "hash",
  routes
});

window.vueRouter = router;

Mount the route to window, and then use window.vueRouter.push where needed

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ead172-2120.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ead172-2120.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?