11import store from '../store' ;
22import * as storage from '../utils/storage' ;
33
4+ const routes = {
5+ asfBans : 'asf-bans' ,
6+ asfConfig : 'asf-config' ,
7+ bot : 'bot' ,
8+ bot2fa : 'bot-2fa' ,
9+ bot2faDelete : 'bot-2fa-delete' ,
10+ botBgr : 'bot-bgr' ,
11+ botConfig : 'bot-config' ,
12+ botCopy : 'bot-copy' ,
13+ botCreate : 'bot-create' ,
14+ botDelete : 'bot-delete' ,
15+ botInput : 'bot-input' ,
16+ bots : 'bots' ,
17+ commands : 'commands' ,
18+ home : 'home' ,
19+ log : 'log' ,
20+ massEditor : 'mass-editor' ,
21+ notFound : '404' ,
22+ passwordEncrypt : 'password-encrypt' ,
23+ passwordHash : 'password-hash' ,
24+ plugins : 'plugins' ,
25+ releases : 'releases' ,
26+ setup : 'setup' ,
27+ uiConfig : 'ui-config' ,
28+ welcome : 'welcome' ,
29+ } ;
30+
431let defaultView = store . getters [ 'settings/defaultView' ] ;
5- if ( defaultView === '_last-visited-page' ) defaultView = storage . get ( 'last-visited-page' , { name : 'home' } ) ;
32+ if ( defaultView === '_last-visited-page' ) defaultView = storage . get ( 'last-visited-page' , routes . home ) ;
33+ if ( ! Object . values ( routes ) . includes ( defaultView ) ) {
34+ defaultView = routes . bots ;
35+ store . dispatch ( 'settings/setDefaultView' , routes . bots ) ;
36+ }
637
738export default [
839 {
940 path : '/' ,
10- redirect : ( typeof defaultView === 'string' ) ? { name : defaultView } : defaultView ,
41+ redirect : { name : defaultView } ,
1142 } ,
1243 {
1344 path : '/home' ,
14- name : ' home' ,
45+ name : routes . home ,
1546 async beforeEnter ( to , from , next ) {
1647 const setupComplete = storage . get ( 'setup-complete' , false ) ;
1748 const botsDetected = await store . dispatch ( 'bots/detectBots' ) ;
1849
19- if ( ! setupComplete && from . name !== ' welcome' && ! botsDetected ) {
20- return next ( { name : ' welcome' } ) ;
50+ if ( ! setupComplete && from . name !== routes . welcome && ! botsDetected ) {
51+ return next ( { name : routes . welcome } ) ;
2152 }
2253
23- if ( from . name === ' welcome' && ! botsDetected ) {
24- return next ( { name : 'bot-create' } ) ;
54+ if ( from . name === routes . welcome && ! botsDetected ) {
55+ return next ( { name : routes . botCreate } ) ;
2556 }
2657
2758 if ( botsDetected ) {
2859 storage . set ( 'setup-complete' , true ) ;
2960 let defaultView = store . getters [ 'settings/defaultView' ] ;
30- if ( defaultView === '_last-visited-page' || defaultView === 'home' ) defaultView = storage . get ( 'last-visited-page' , { name : 'bots' } ) ;
31- const page = ( typeof defaultView === 'string' ) ? { name : defaultView } : defaultView ;
32- return next ( page ) ;
61+ if ( defaultView === '_last-visited-page' ) defaultView = storage . get ( 'last-visited-page' , routes . bots ) ;
62+ if ( ! Object . values ( routes ) . includes ( defaultView ) || defaultView === routes . home ) {
63+ defaultView = routes . bots ;
64+ store . dispatch ( 'settings/setDefaultView' , routes . bots ) ;
65+ }
66+ return next ( { name : defaultView } ) ;
3367 }
3468
35- return next ( { name : ' bots' } ) ;
69+ return next ( { name : routes . bots } ) ;
3670 } ,
3771 } ,
3872 {
3973 path : '/setup' ,
40- name : ' setup' ,
74+ name : routes . setup ,
4175 component : ( ) => import ( '../views/Setup.vue' ) ,
4276 meta : { noPasswordRequired : true } ,
4377 params : {
@@ -47,199 +81,199 @@ export default [
4781 } ,
4882 {
4983 path : '/ui-config' ,
50- name : 'ui-config' ,
84+ name : routes . uiConfig ,
5185 component : ( ) => import ( '../views/UIConfig.vue' ) ,
5286 } ,
5387 {
5488 path : '/welcome' ,
55- name : ' welcome' ,
89+ name : routes . welcome ,
5690 component : ( ) => import ( '../views/Welcome.vue' ) ,
5791 meta : { noPasswordRequired : true } ,
5892 } ,
5993 {
6094 path : '/releases' ,
61- name : ' releases' ,
95+ name : routes . releases ,
6296 component : ( ) => import ( '../views/Releases.vue' ) ,
6397 } ,
6498 {
6599 path : '/plugins' ,
66- name : ' plugins' ,
100+ name : routes . plugins ,
67101 component : ( ) => import ( '../views/Plugins.vue' ) ,
68102 } ,
69103 {
70104 path : '/bots' ,
71- name : ' bots' ,
105+ name : routes . bots ,
72106 component : ( ) => import ( '../views/Bots.vue' ) ,
73107 } ,
74108 {
75109 path : '/bot/new' ,
76- name : 'bot-create' ,
110+ name : routes . botCreate ,
77111 components : {
78112 default : ( ) => import ( '../views/Bots.vue' ) ,
79113 modal : ( ) => import ( '../views/modals/BotCreate.vue' ) ,
80114 } ,
81115 meta : {
82116 modal : true ,
83- closeRoute : ' bots' ,
117+ closeRoute : routes . bots ,
84118 } ,
85119 } ,
86120 {
87121 path : '/bot/:bot' ,
88- name : ' bot' ,
122+ name : routes . bot ,
89123 components : {
90124 default : ( ) => import ( '../views/Bots.vue' ) ,
91125 modal : ( ) => import ( '../views/modals/Bot.vue' ) ,
92126 } ,
93127 meta : {
94128 modal : true ,
95129 arrows : true ,
96- closeRoute : ' bots' ,
130+ closeRoute : routes . bots ,
97131 } ,
98132 } ,
99133 {
100134 path : '/bot/:bot/config' ,
101- name : 'bot-config' ,
135+ name : routes . botConfig ,
102136 components : {
103137 default : ( ) => import ( '../views/Bots.vue' ) ,
104138 modal : ( ) => import ( '../views/modals/BotConfig.vue' ) ,
105139 } ,
106140 meta : {
107141 modal : true ,
108142 arrows : true ,
109- closeRoute : ' bots' ,
143+ closeRoute : routes . bots ,
110144 } ,
111145 } ,
112146 {
113147 path : '/bot/:bot/config/:label/encrypt' ,
114- name : 'password-encrypt' ,
148+ name : routes . passwordEncrypt ,
115149 components : {
116150 default : ( ) => import ( '../views/Bots.vue' ) ,
117151 modal : ( ) => import ( '../views/modals/PasswordEncrypt.vue' ) ,
118152 } ,
119153 meta : {
120154 modal : true ,
121- closeRoute : ' bots' ,
155+ closeRoute : routes . bots ,
122156 } ,
123157 } ,
124158 {
125159 path : '/bot/:bot/bgr' ,
126- name : 'bot-bgr' ,
160+ name : routes . botBgr ,
127161 components : {
128162 default : ( ) => import ( '../views/Bots.vue' ) ,
129163 modal : ( ) => import ( '../views/modals/BotBGR.vue' ) ,
130164 } ,
131165 meta : {
132166 modal : true ,
133167 arrows : true ,
134- closeRoute : ' bots' ,
168+ closeRoute : routes . bots ,
135169 } ,
136170 } ,
137171 {
138172 path : '/bot/:bot/2fa' ,
139- name : 'bot-2fa' ,
173+ name : routes . bot2fa ,
140174 components : {
141175 default : ( ) => import ( '../views/Bots.vue' ) ,
142176 modal : ( ) => import ( '../views/modals/Bot2FA.vue' ) ,
143177 } ,
144178 meta : {
145179 modal : true ,
146180 arrows : true ,
147- closeRoute : ' bots' ,
181+ closeRoute : routes . bots ,
148182 } ,
149183 } ,
150184 {
151185 path : '/bot/:bot/2fa/delete' ,
152- name : 'bot-2fa-delete' ,
186+ name : routes . bot2faDelete ,
153187 components : {
154188 default : ( ) => import ( '../views/Bots.vue' ) ,
155189 modal : ( ) => import ( '../views/modals/Bot2FADelete.vue' ) ,
156190 } ,
157191 meta : {
158192 modal : true ,
159193 arrows : true ,
160- closeRoute : ' bots' ,
194+ closeRoute : routes . bots ,
161195 } ,
162196 } ,
163197 {
164198 path : '/bot/:bot/input/:type' ,
165- name : 'bot-input' ,
199+ name : routes . botInput ,
166200 components : {
167201 default : ( ) => import ( '../views/Bots.vue' ) ,
168202 modal : ( ) => import ( '../views/modals/BotInput.vue' ) ,
169203 } ,
170204 meta : {
171205 modal : true ,
172- closeRoute : ' bots' ,
206+ closeRoute : routes . bots ,
173207 } ,
174208 } ,
175209 {
176210 path : '/bot/:bot/delete' ,
177- name : 'bot-delete' ,
211+ name : routes . botDelete ,
178212 components : {
179213 default : ( ) => import ( '../views/Bots.vue' ) ,
180214 modal : ( ) => import ( '../views/modals/BotDelete.vue' ) ,
181215 } ,
182216 meta : {
183217 modal : true ,
184- closeRoute : ' bots' ,
218+ closeRoute : routes . bots ,
185219 } ,
186220 } ,
187221 {
188222 path : '/bot/:bot/copy' ,
189- name : 'bot-copy' ,
223+ name : routes . botCopy ,
190224 components : {
191225 default : ( ) => import ( '../views/Bots.vue' ) ,
192226 modal : ( ) => import ( '../views/modals/BotCopy.vue' ) ,
193227 } ,
194228 meta : {
195229 modal : true ,
196- closeRoute : ' bots' ,
230+ closeRoute : routes . bots ,
197231 } ,
198232 } ,
199233 {
200234 path : '/bot' ,
201- redirect : { name : ' bots' } ,
235+ redirect : { name : routes . bots } ,
202236 } ,
203237 {
204238 path : '/commands' ,
205- name : ' commands' ,
239+ name : routes . commands ,
206240 component : ( ) => import ( '../views/Commands.vue' ) ,
207241 } ,
208242 {
209243 path : '/log' ,
210- name : ' log' ,
244+ name : routes . log ,
211245 component : ( ) => import ( '../views/Log.vue' ) ,
212246 } ,
213247 {
214248 path : '/asf-config' ,
215- name : 'asf-config' ,
249+ name : routes . asfConfig ,
216250 component : ( ) => import ( '../views/ASFConfig.vue' ) ,
217251 } ,
218252 {
219253 path : '/asf-bans' ,
220- name : 'asf-bans' ,
254+ name : routes . asfBans ,
221255 component : ( ) => import ( '../views/ASFBans.vue' ) ,
222256 } ,
223257 {
224258 path : '/asf-config/:label/hash' ,
225- name : 'password-hash' ,
259+ name : routes . passwordHash ,
226260 components : {
227261 default : ( ) => import ( '../views/ASFConfig.vue' ) ,
228262 modal : ( ) => import ( '../views/modals/PasswordHash.vue' ) ,
229263 } ,
230264 meta : {
231265 modal : true ,
232- closeRoute : 'asf-config' ,
266+ closeRoute : routes . asfConfig ,
233267 } ,
234268 } ,
235269 {
236270 path : '/mass-editor' ,
237- name : 'mass-editor' ,
271+ name : routes . massEditor ,
238272 component : ( ) => import ( '../views/MassEditor.vue' ) ,
239273 } ,
240274 {
241275 path : '*' ,
242- name : '404' ,
243- redirect : { name : ' home' } ,
276+ name : routes . notFound ,
277+ redirect : { name : routes . home } ,
244278 } ,
245279] ;
0 commit comments