@@ -5,78 +5,79 @@ import ProjectsView from '@/views/ProjectsView.vue';
55import ProjectDetailView from '@/views/ProjectDetailView.vue' ;
66import { isHostedMode } from '@/composables/useHostedMode' ;
77
8- const hostedMode = isHostedMode ( ) ;
98const hostedRoot = '/app/swatch' ;
109const hostedTitle = 'Filament Swatch' ;
1110const standaloneTitle = 'Spool Swatch' ;
12- const titlePrefix = hostedMode ? hostedTitle : standaloneTitle ;
11+ export const createAppRouter = ( ) => {
12+ const hostedMode = isHostedMode ( ) ;
13+ const titlePrefix = hostedMode ? hostedTitle : standaloneTitle ;
1314
14- const router = createRouter ( {
15- history : createWebHistory ( import . meta. env . BASE_URL ) ,
16- routes : [
17- hostedMode
18- ? {
19- path : '/' ,
20- redirect : hostedRoot ,
21- }
22- : {
23- path : '/' ,
24- name : 'landing' ,
25- component : LandingPage ,
26- meta : {
27- title : `${ titlePrefix } - Your 3D Printing Filament Color Browser`
15+ const router = createRouter ( {
16+ history : createWebHistory ( import . meta. env . BASE_URL ) ,
17+ routes : [
18+ hostedMode
19+ ? {
20+ path : '/' ,
21+ redirect : hostedRoot ,
2822 }
29- } ,
30- {
31- path : '/app' ,
32- component : MainApp ,
33- redirect : hostedRoot ,
34- children : [
35- {
36- path : 'swatch' ,
37- name : 'swatch' ,
38- component : ( ) => import ( '@/views/FilamentsView.vue' ) ,
39- meta : {
40- title : `${ titlePrefix } - Browse Your Collection`
23+ : {
24+ path : '/' ,
25+ name : 'landing' ,
26+ component : LandingPage ,
27+ meta : {
28+ title : `${ titlePrefix } - Your 3D Printing Filament Color Browser`
29+ }
30+ } ,
31+ {
32+ path : '/app' ,
33+ component : MainApp ,
34+ redirect : hostedRoot ,
35+ children : [
36+ {
37+ path : 'swatch' ,
38+ name : 'swatch' ,
39+ component : ( ) => import ( '@/views/FilamentsView.vue' ) ,
40+ meta : {
41+ title : `${ titlePrefix } - Browse Your Collection`
42+ }
43+ } ,
44+ {
45+ path : 'projects' ,
46+ name : 'projects' ,
47+ component : ProjectsView ,
48+ meta : {
49+ title : `${ titlePrefix } - Projects`
50+ }
51+ } ,
52+ {
53+ path : 'projects/:id' ,
54+ name : 'project-detail' ,
55+ component : ProjectDetailView ,
56+ meta : {
57+ title : `${ titlePrefix } - Project Details`
58+ }
4159 }
42- } ,
43- {
44- path : 'projects' ,
45- name : 'projects' ,
46- component : ProjectsView ,
47- meta : {
48- title : `${ titlePrefix } - Projects`
49- }
50- } ,
51- {
52- path : 'projects/:id' ,
53- name : 'project-detail' ,
54- component : ProjectDetailView ,
55- meta : {
56- title : `${ titlePrefix } - Project Details`
57- }
58- }
59- ]
60- } ,
61- // Catch-all redirect for unknown routes
62- {
63- path : '/:pathMatch(.*)*' ,
64- redirect : hostedMode ? hostedRoot : '/'
65- }
66- ] ,
67- scrollBehavior ( to , from , savedPosition ) {
68- if ( savedPosition ) {
69- return savedPosition ;
70- } else {
71- return { top : 0 } ;
60+ ]
61+ } ,
62+ // Catch-all redirect for unknown routes
63+ {
64+ path : '/:pathMatch(.*)*' ,
65+ redirect : hostedMode ? hostedRoot : '/'
66+ }
67+ ] ,
68+ scrollBehavior ( to , from , savedPosition ) {
69+ if ( savedPosition ) {
70+ return savedPosition ;
71+ } else {
72+ return { top : 0 } ;
73+ }
7274 }
73- }
74- } ) ;
75+ } ) ;
7576
76- // Update document title on route change
77- router . beforeEach ( ( to , from , next ) => {
78- document . title = ( to . meta . title as string ) || titlePrefix ;
79- next ( ) ;
80- } ) ;
77+ router . beforeEach ( ( to , from , next ) => {
78+ document . title = ( to . meta . title as string ) || titlePrefix ;
79+ next ( ) ;
80+ } ) ;
8181
82- export default router ;
82+ return router ;
83+ } ;
0 commit comments