index.coffee 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # app/router/index.coffee
  2. config = require 'app/config'
  3. # Middleware для проверки прав доступа
  4. authGuard = (to, from, next) ->
  5. log 'Проверка прав доступа для route:', to.path
  6. # Здесь будет логика проверки пользователя из глобального состояния
  7. if to.matched.some (record) -> record.meta.requiresAuth
  8. # Проверка авторизации
  9. next() # Временная заглушка - всегда разрешаем доступ
  10. else
  11. next()
  12. domainMiddleware = (to, from, next) ->
  13. log 'Обработка динамического домена для route'
  14. # Логика обработки домена будет интегрирована позже
  15. next()
  16. router = VueRouter.createRouter({
  17. history: VueRouter.createWebHistory()
  18. routes: [
  19. {
  20. path: '/'
  21. name: 'Home'
  22. component: require 'app/pages/Home/index.coffee'
  23. beforeEnter: [domainMiddleware]
  24. }
  25. {
  26. path: '/catalog'
  27. name: 'Catalog'
  28. component: require 'app/pages/Catalog/index.coffee'
  29. beforeEnter: [domainMiddleware]
  30. }
  31. {
  32. path: '/catalog/:category?'
  33. name: 'CatalogCategory'
  34. component: require 'app/pages/Catalog/index.coffee'
  35. beforeEnter: [domainMiddleware]
  36. }
  37. {
  38. path: '/product/:id'
  39. name: 'Product'
  40. component: require 'app/pages/Product/index.coffee'
  41. beforeEnter: [domainMiddleware]
  42. }
  43. {
  44. path: '/cart'
  45. name: 'Cart'
  46. component: require 'app/pages/Cart/index.coffee'
  47. beforeEnter: [domainMiddleware]
  48. }
  49. {
  50. path: '/admin'
  51. name: 'Admin'
  52. component: require 'app/pages/Admin/index.coffee'
  53. meta: { requiresAuth: true }
  54. beforeEnter: [domainMiddleware, authGuard]
  55. }
  56. {
  57. path: '/:pathMatch(.*)*'
  58. name: 'NotFound'
  59. component: require 'app/pages/NotFound/index.coffee'
  60. beforeEnter: [domainMiddleware]
  61. }
  62. ]
  63. })
  64. # Глобальные обработчики роутера
  65. router.beforeEach (to, from, next) ->
  66. #log "Переход с "+ from.fullPath +" на "+to.fullPath+""
  67. next()
  68. router.afterEach (to, from) ->
  69. #log "Навигация завершена на "+to.fullPath+""
  70. module.exports = router