npm install --save vue3-router
In main.js
import { createApp } from 'vue'
import App from './App.vue'
import { vue3Route } from 'vue3-router'
createApp(App)
.component('vue3-router', vue3Route)
.use(vue3Route)
.mount('#app')
In App.vue, use the component:
<vue3-router />
- Create a dir
./src/router
- Create a file
./src/router/index.js
- Create your routes.
Example:
import Home from '@/components/Home'
const myFirstRoute = () => 'Hello! This is a my first route!'
const routes = [
{
path: '/',
component: Home,
auth: false
},
{
path: '/vue3-router',
component: () => 'Welcome to package vue3-router',
auth: false
},
{
path: '/my-first-route',
component: myFirstRoute,
auth: false
}
]
export {
routes
}