create-packer 1.17.28 → 1.17.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/react/src/router/home/index.ts +1 -1
- package/template/react/src/router/home/routes.tsx +2 -2
- package/template/react/src/router/{names.ts → ids.ts} +1 -1
- package/template/react/src/router/index.ts +1 -1
- package/template/react/src/router/router.provider.ts +24 -5
- package/template/react/src/router/router.tsx +12 -10
- package/template/react/src/router/router.types.ts +1 -4
- /package/template/react/src/router/home/{names.ts → ids.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as routes } from './routes'
|
|
2
|
-
export { default as
|
|
2
|
+
export { default as ids } from './ids'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { lazy } from 'react'
|
|
2
|
-
import
|
|
2
|
+
import ids from './ids'
|
|
3
3
|
import type { routeType } from '../router.types'
|
|
4
4
|
|
|
5
5
|
const routes: routeType[] = [
|
|
6
6
|
{
|
|
7
7
|
index: true,
|
|
8
|
-
|
|
8
|
+
id: ids.home,
|
|
9
9
|
Component: lazy(() => import('@/pages/home'))
|
|
10
10
|
}
|
|
11
11
|
]
|
|
@@ -1,22 +1,41 @@
|
|
|
1
1
|
import { find, get } from 'lodash-es'
|
|
2
2
|
import { stringify } from 'qs'
|
|
3
|
-
import { NavigateOptions
|
|
3
|
+
import { NavigateOptions } from 'react-router-dom'
|
|
4
|
+
import { routeType } from '@/router/router.types'
|
|
4
5
|
import { router, routesList } from './router'
|
|
5
6
|
|
|
6
|
-
export function getRoute(
|
|
7
|
-
const route = find(routesList, o => o.
|
|
7
|
+
export function getRoute(id: routeType['id'], path?: string | string[]) {
|
|
8
|
+
const route = find(routesList, o => o.id === id)
|
|
8
9
|
if (path) {
|
|
9
10
|
return get(route, path)
|
|
10
11
|
}
|
|
11
12
|
return route
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
export function genRouteUrl(id: routeType['id'], query?: Record<string, any>) {
|
|
16
|
+
const path = getRoute(id, 'path')
|
|
17
|
+
if (path) {
|
|
18
|
+
const { origin } = window.location
|
|
19
|
+
let url = origin + import.meta.env.VITE_BASE_URL + path
|
|
20
|
+
url += query ? `?${stringify(query)}` : ''
|
|
21
|
+
return url
|
|
22
|
+
}
|
|
23
|
+
return void 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function openRoute(id: routeType['id'], query?: Record<string, any>) {
|
|
27
|
+
const url = genRouteUrl(id, query)
|
|
28
|
+
if (url) {
|
|
29
|
+
window.open(url)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
14
33
|
export function navigate(
|
|
15
|
-
to: {
|
|
34
|
+
to: { id: routeType['id']; query?: Record<string, any> },
|
|
16
35
|
opts?: NavigateOptions
|
|
17
36
|
) {
|
|
18
37
|
return router.navigate(
|
|
19
|
-
{ pathname: getRoute(to.
|
|
38
|
+
{ pathname: getRoute(to.id, 'path'), search: to.query ? stringify(to.query) : '' },
|
|
20
39
|
opts
|
|
21
40
|
)
|
|
22
41
|
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { lazy } from 'react'
|
|
2
|
-
import { concat, isArray, reduce } from 'lodash-es'
|
|
3
2
|
import { createBrowserRouter } from 'react-router-dom'
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import { concat, isArray, reduce } from 'lodash-es'
|
|
4
|
+
import ids from './ids'
|
|
6
5
|
import type { routeType } from './router.types'
|
|
7
6
|
|
|
8
7
|
const routes: routeType[] = [
|
|
9
8
|
{
|
|
10
9
|
path: '/',
|
|
11
|
-
|
|
10
|
+
id: ids.root,
|
|
12
11
|
Component: lazy(() => import('@/layout')),
|
|
13
|
-
children: [
|
|
12
|
+
children: []
|
|
14
13
|
},
|
|
15
14
|
{
|
|
16
15
|
path: '*',
|
|
17
|
-
|
|
16
|
+
id: '404',
|
|
18
17
|
Component: lazy(() => import('@/pages/notFound'))
|
|
19
18
|
}
|
|
20
19
|
]
|
|
20
|
+
|
|
21
21
|
export const routesList = (function flat(routes: routeType[], parentRoute?: routeType) {
|
|
22
22
|
return reduce(
|
|
23
23
|
routes,
|
|
24
24
|
(result, route) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (parentRoute) {
|
|
26
|
+
route.path = `${parentRoute.path === '/' ? '' : parentRoute.path}/${route.path}`
|
|
27
|
+
}
|
|
28
28
|
result.push(route)
|
|
29
29
|
if (isArray(route.children)) {
|
|
30
30
|
result = concat(result, flat(route.children, route))
|
|
@@ -34,4 +34,6 @@ export const routesList = (function flat(routes: routeType[], parentRoute?: rout
|
|
|
34
34
|
[] as routeType[]
|
|
35
35
|
)
|
|
36
36
|
})(routes)
|
|
37
|
-
export const router = createBrowserRouter(routes as never
|
|
37
|
+
export const router = createBrowserRouter(routes as never, {
|
|
38
|
+
basename: import.meta.env.VITE_BASE_URL
|
|
39
|
+
})
|
|
File without changes
|