Giter VIP home page Giter VIP logo

Comments (5)

markthree avatar markthree commented on August 19, 2024

路由守卫可以在 modules 下的 router.ts 中注册。

import { App } from 'vue'
import generatedRoutes from 'virtual:generated-pages'
import { setupLayouts } from 'virtual:generated-layouts'
import { createRouter, createWebHistory } from 'vue-router'

const routes = setupLayouts(generatedRoutes)

export const router = createRouter({
	routes,
	history: createWebHistory()
})

// 此处书写各种路由守卫
router.beforeEach(v => {
	console.log(v)
})

export default (app: App) => app.use(router)

from tov-template.

markthree avatar markthree commented on August 19, 2024

甚至你可以在其他任意地方引入该 router 实例后注册路由守卫。

例如你可以在 src 目录下创建一个 router.ts

// src/guard.ts
import { router } from "~/modules/router"

// 此处书写各种路由守卫
router.beforeEach(v => {
	console.log(v)
})

最后在 src/main.ts 中引入即可

import "~/guard"
// ....

from tov-template.

1185497683 avatar 1185497683 commented on August 19, 2024

谢谢啦,非常赞!

from tov-template.

1185497683 avatar 1185497683 commented on August 19, 2024

通常是基于axios插入事件来做路由守卫,这里api请求用的是vueRequest,怎么结合vueRequest呢?

from tov-template.

markthree avatar markthree commented on August 19, 2024

通常是基于axios插入事件来做路由守卫,这里api请求用的是vueRequest,怎么结合vueRequest呢?

靓仔你好,vueRequest 是一个比较偏执的请求库,你可以结合 axios 来,具体可见 VueRequest

from tov-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.