-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathrouter.tsx
More file actions
144 lines (137 loc) · 4.23 KB
/
router.tsx
File metadata and controls
144 lines (137 loc) · 4.23 KB
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
import React from 'react';
import type { RouteObject } from 'react-router-dom';
import { createBrowserRouter } from 'react-router-dom';
import type { TemplatePageLoaderData } from './pages/template-page/template-page';
import type { TemplatesPageLoaderData } from './pages/templates-page/templates-page';
import { getTemplatesAndAllTags } from './templates-data/template-utils';
const routes: RouteObject[] = [
...['', 'diagrams/:diagramId'].map((path) => ({
path,
async lazy() {
const { EditorPage } =
await import('./pages/editor-page/editor-page');
return {
element: <EditorPage />,
};
},
})),
{
path: 'examples',
async lazy() {
const { ExamplesPage } =
await import('./pages/examples-page/examples-page');
return {
element: <ExamplesPage />,
};
},
},
{
id: 'templates',
path: 'templates',
async lazy() {
const { TemplatesPage } =
await import('./pages/templates-page/templates-page');
return {
element: <TemplatesPage />,
};
},
loader: async (): Promise<TemplatesPageLoaderData> => {
const { tags, templates } = await getTemplatesAndAllTags();
return {
allTags: tags,
templates,
};
},
},
{
id: 'templates_featured',
path: 'templates/featured',
async lazy() {
const { TemplatesPage } =
await import('./pages/templates-page/templates-page');
return {
element: <TemplatesPage />,
};
},
loader: async (): Promise<TemplatesPageLoaderData> => {
const { tags, templates } = await getTemplatesAndAllTags({
featured: true,
});
return {
allTags: tags,
templates,
};
},
},
{
id: 'templates_tags',
path: 'templates/tags/:tag',
async lazy() {
const { TemplatesPage } =
await import('./pages/templates-page/templates-page');
return {
element: <TemplatesPage />,
};
},
loader: async ({ params }): Promise<TemplatesPageLoaderData> => {
const { tags, templates } = await getTemplatesAndAllTags({
tag: params.tag?.replace(/-/g, ' '),
});
return {
allTags: tags,
templates,
};
},
},
{
id: 'templates_templateSlug',
path: 'templates/:templateSlug',
async lazy() {
const { TemplatePage } =
await import('./pages/template-page/template-page');
return {
element: <TemplatePage />,
};
},
loader: async ({ params }): Promise<TemplatePageLoaderData> => {
const { templates } =
await import('./templates-data/templates-data');
return {
template: templates.find(
(template) => template.slug === params.templateSlug
),
};
},
},
{
id: 'templates_load',
path: 'templates/clone/:templateSlug',
async lazy() {
const { CloneTemplatePage } =
await import('./pages/clone-template-page/clone-template-page');
return {
element: <CloneTemplatePage />,
};
},
loader: async ({ params }) => {
const { templates } =
await import('./templates-data/templates-data');
return {
template: templates.find(
(template) => template.slug === params.templateSlug
),
};
},
},
{
path: '*',
async lazy() {
const { NotFoundPage } =
await import('./pages/not-found-page/not-found-page');
return {
element: <NotFoundPage />,
};
},
},
];
export const router = createBrowserRouter(routes);