forked from frappe/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.ts
156 lines (148 loc) · 3.68 KB
/
router.ts
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
147
148
149
150
151
152
153
154
155
156
import ChartOfAccounts from 'src/pages/ChartOfAccounts.vue';
import CommonForm from 'src/pages/CommonForm/CommonForm.vue';
import Dashboard from 'src/pages/Dashboard/Dashboard.vue';
import GetStarted from 'src/pages/GetStarted.vue';
import ImportWizard from 'src/pages/ImportWizard.vue';
import ListView from 'src/pages/ListView/ListView.vue';
import PrintView from 'src/pages/PrintView/PrintView.vue';
import ReportPrintView from 'src/pages/PrintView/ReportPrintView.vue';
import QuickEditForm from 'src/pages/QuickEditForm.vue';
import Report from 'src/pages/Report.vue';
import Settings from 'src/pages/Settings/Settings.vue';
import TemplateBuilder from 'src/pages/TemplateBuilder/TemplateBuilder.vue';
import CustomizeForm from 'src/pages/CustomizeForm/CustomizeForm.vue';
import POS from 'src/pages/POS/POS.vue';
import type { HistoryState } from 'vue-router';
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import { historyState } from './utils/refs';
const routes: RouteRecordRaw[] = [
{
path: '/',
component: Dashboard,
},
{
path: '/get-started',
component: GetStarted,
},
{
path: `/edit/:schemaName/:name`,
name: `CommonForm`,
components: {
default: CommonForm,
edit: QuickEditForm,
},
props: {
default: (route) => ({
schemaName: route.params.schemaName,
name: route.params.name,
}),
edit: (route) => route.query,
},
},
{
path: '/list/:schemaName/:pageTitle?',
name: 'ListView',
components: {
default: ListView,
edit: QuickEditForm,
},
props: {
default: (route) => {
const { schemaName } = route.params;
const pageTitle = route.params.pageTitle ?? '';
const filters = {};
const filterString = route.query.filters;
if (typeof filterString === 'string') {
Object.assign(filters, JSON.parse(filterString));
}
return {
schemaName,
filters,
pageTitle,
};
},
edit: (route) => route.query,
},
},
{
path: '/print/:schemaName/:name',
name: 'PrintView',
component: PrintView,
props: true,
},
{
path: '/report-print/:reportName',
name: 'ReportPrintView',
component: ReportPrintView,
props: true,
},
{
path: '/report/:reportClassName',
name: 'Report',
component: Report,
props: true,
},
{
path: '/chart-of-accounts',
name: 'Chart Of Accounts',
components: {
default: ChartOfAccounts,
edit: QuickEditForm,
},
props: {
default: true,
edit: (route) => route.query,
},
},
{
path: '/import-wizard',
name: 'Import Wizard',
component: ImportWizard,
},
{
path: '/template-builder/:name',
name: 'Template Builder',
component: TemplateBuilder,
props: true,
},
{
path: '/customize-form',
name: 'Customize Form',
component: CustomizeForm,
},
{
path: '/settings',
name: 'Settings',
components: {
default: Settings,
edit: QuickEditForm,
},
props: {
default: true,
edit: (route) => route.query,
},
},
{
path: '/pos',
name: 'Point of Sale',
components: {
default: POS,
edit: QuickEditForm,
},
props: {
default: true,
edit: (route) => route.query,
},
},
];
const router = createRouter({ routes, history: createWebHistory() });
router.afterEach(({ fullPath }) => {
const state = history.state as HistoryState;
historyState.forward = !!state.forward;
historyState.back = !!state.back;
if (fullPath.includes('index.html')) {
return;
}
localStorage.setItem('lastRoute', fullPath);
});
export default router;