init
This commit is contained in:
@@ -2,14 +2,109 @@ import { createRouter, createWebHistory } from 'vue-router'
|
||||
import CalculatorView from '../views/CalculatorView.vue'
|
||||
import MaterialsView from '../views/MaterialsView.vue'
|
||||
import OrderView from '../views/OrderView.vue'
|
||||
import BlogView from '../views/BlogView.vue'
|
||||
import ArticleView from '../views/ArticleView.vue'
|
||||
import AdminLogin from '../views/admin/AdminLogin.vue'
|
||||
import AdminLayout from '../views/admin/AdminLayout.vue'
|
||||
import AdminDashboard from '../views/admin/AdminDashboard.vue'
|
||||
import AdminOrders from '../views/admin/AdminOrders.vue'
|
||||
import AdminMaterials from '../views/admin/AdminMaterials.vue'
|
||||
import AdminSettings from '../views/admin/AdminSettings.vue'
|
||||
import AdminUsers from '../views/admin/AdminUsers.vue'
|
||||
|
||||
const routes = [
|
||||
{ path: '/', name: 'calculator', component: CalculatorView },
|
||||
{ path: '/materials', name: 'materials', component: MaterialsView },
|
||||
{ path: '/order/:calcId', name: 'order', component: OrderView },
|
||||
{
|
||||
path: '/',
|
||||
name: 'calculator',
|
||||
component: CalculatorView,
|
||||
meta: { title: 'Калькулятор 3D-печати — Filam3D' },
|
||||
},
|
||||
{
|
||||
path: '/materials',
|
||||
name: 'materials',
|
||||
component: MaterialsView,
|
||||
meta: { title: 'Материалы для 3D-печати — Filam3D' },
|
||||
},
|
||||
{
|
||||
path: '/order/:calcId',
|
||||
name: 'order',
|
||||
component: OrderView,
|
||||
meta: { title: 'Оформление заказа — Filam3D' },
|
||||
},
|
||||
{
|
||||
path: '/blog',
|
||||
name: 'blog',
|
||||
component: BlogView,
|
||||
meta: { title: 'Блог о 3D-печати — статьи и руководства — Filam3D' },
|
||||
},
|
||||
{
|
||||
path: '/blog/:slug',
|
||||
name: 'article',
|
||||
component: ArticleView,
|
||||
},
|
||||
{
|
||||
path: '/admin/login',
|
||||
name: 'admin-login',
|
||||
component: AdminLogin,
|
||||
meta: { title: 'Вход — Админ-панель Filam3D' },
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
component: AdminLayout,
|
||||
meta: { requiresAdmin: true },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'admin-dashboard',
|
||||
component: AdminDashboard,
|
||||
meta: { title: 'Дашборд — Админ-панель Filam3D' },
|
||||
},
|
||||
{
|
||||
path: 'orders',
|
||||
name: 'admin-orders',
|
||||
component: AdminOrders,
|
||||
meta: { title: 'Заказы — Админ-панель Filam3D' },
|
||||
},
|
||||
{
|
||||
path: 'materials',
|
||||
name: 'admin-materials',
|
||||
component: AdminMaterials,
|
||||
meta: { title: 'Материалы — Админ-панель Filam3D' },
|
||||
},
|
||||
{
|
||||
path: 'settings',
|
||||
name: 'admin-settings',
|
||||
component: AdminSettings,
|
||||
meta: { title: 'Настройки — Админ-панель Filam3D' },
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
name: 'admin-users',
|
||||
component: AdminUsers,
|
||||
meta: { title: 'Администраторы — Админ-панель Filam3D' },
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export default createRouter({
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
scrollBehavior() {
|
||||
return { top: 0 }
|
||||
},
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
if (to.meta.title) {
|
||||
document.title = to.meta.title
|
||||
}
|
||||
if (to.meta.requiresAdmin || to.matched.some((r) => r.meta.requiresAdmin)) {
|
||||
const token = localStorage.getItem('admin_token')
|
||||
if (!token) {
|
||||
return { name: 'admin-login' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user