Где в VUE прописаны роуты?
В Vue роуты прописываются не в самом компоненте, а в Vue Router — обычно в отдельном файле.
Где именно смотреть 👇
1️⃣ Vue 2 / Vue 3 (самый частый вариант)
Обычно файл:
src/router/index.js
или
src/router/index.ts
Пример:
import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
component: () => import('@/views/About.vue')
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
export default router
2️⃣ Где роутер подключается к приложению
Обычно в:
src/main.js
или
src/main.ts
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
createApp(App)
.use(router)
.mount('#app')
3️⃣ Если используется Nuxt
Тогда роуты не прописываются вручную:
pages/
Структура папок = маршруты
Например:
pages/index.vue → /
pages/login.vue → /login
pages/user/_id.vue → /user/:id
4️⃣ Как быстро понять в чужом проекте
-
Ищи папку
router -
Или файл с
createRouter/VueRouter -
Или в
package.jsonпроверь зависимость:
"vue-router"
No comments to display
No comments to display