Vue-Router
Vue-Router in Vue3
install
| npm install vue-router@4.0.0-beta.13
|
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import { createRouter, createWebHashHistory } from "vue-router"
const routes = [ { path: "/", redirect: "/home" }, { path: "/home", name: "home", component: () => import("../home") }, { path: "/login", name: "login", component: () => import("../login") } ]
export const router = createRouter({ history: createWebHashHistory(), routes: routes })
import { createApp } from 'vue' import App from './App.vue' import { router } from './route'
const app = createApp(App) app.use(router) app.mount('#app')
import { useRouter } from 'vue-router'
const router = useRouter(); router.push('/login')
|