-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathrouter.js
146 lines (136 loc) · 3.78 KB
/
router.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import Vue from 'vue'
import Router from 'vue-router'
import { apolloClient } from './vue-apollo'
import ProjectHome from './components/app/ProjectHome.vue'
import ProjectDashboard from './components/dashboard/ProjectDashboard.vue'
import ProjectPlugins from './components/plugin/ProjectPlugins.vue'
import ProjectPluginsAdd from './components/plugin/ProjectPluginsAdd.vue'
import ProjectConfigurations from './components/configuration/ProjectConfigurations.vue'
import ProjectConfigurationDetails from './components/configuration/ProjectConfigurationDetails.vue'
import ProjectTasks from './components/task/ProjectTasks.vue'
import ProjectTaskDetails from './components/task/ProjectTaskDetails.vue'
import ProjectDependencies from './components/dependency/ProjectDependencies.vue'
import ProjectSelect from './components/project-manager/ProjectSelect.vue'
import ProjectCreate from './components/project-create/ProjectCreate.vue'
import FileDiffView from './components/file-diff/FileDiffView.vue'
import About from './components/app/About.vue'
import NotFound from './components/app/NotFound.vue'
import PROJECT_CURRENT from './graphql/project/projectCurrent.gql'
import CURRENT_PROJECT_ID_SET from './graphql/project/currentProjectIdSet.gql'
Vue.use(Router)
const router = new Router({
mode: 'history',
routes: [
{
path: '/',
component: ProjectHome,
meta: {
needProject: true
},
children: [
{
path: '',
name: 'project-home',
redirect: { name: 'project-dashboard' }
},
{
path: 'dashboard',
name: 'project-dashboard',
component: ProjectDashboard
},
{
path: 'plugins',
name: 'project-plugins',
component: ProjectPlugins
},
{
path: 'plugins/add',
name: 'project-plugins-add',
component: ProjectPluginsAdd
},
{
path: 'configuration',
name: 'project-configurations',
component: ProjectConfigurations,
children: [
{
path: ':id',
name: 'project-configuration-details',
component: ProjectConfigurationDetails,
props: true
}
]
},
{
path: 'tasks',
name: 'project-tasks',
component: ProjectTasks,
children: [
{
path: ':id',
name: 'project-task-details',
component: ProjectTaskDetails,
props: true
}
]
},
{
path: 'dependencies',
name: 'project-dependencies',
component: ProjectDependencies
}
]
},
{
path: '/project/select',
name: 'project-select',
component: ProjectSelect
},
{
path: '/project/create',
name: 'project-create',
component: ProjectCreate
},
{
path: '/file-diff',
name: 'file-diff',
component: FileDiffView
},
{
path: '/about',
name: 'about',
component: About
},
{
path: '/home',
name: 'home',
redirect: { name: 'project-home' }
},
{
path: '*',
name: 'not-found',
component: NotFound
}
]
})
router.beforeEach(async (to, from, next) => {
if (to.matched.some(m => m.meta.needProject)) {
const result = await apolloClient.query({
query: PROJECT_CURRENT,
fetchPolicy: 'network-only'
})
if (!result.data.projectCurrent) {
next({ name: 'project-select' })
return
} else {
await apolloClient.mutate({
mutation: CURRENT_PROJECT_ID_SET,
variables: {
projectId: result.data.projectCurrent.id
}
})
}
}
next()
})
export default router