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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-packer",
3
- "version": "1.17.28",
3
+ "version": "1.17.29",
4
4
  "main": "index.js",
5
5
  "repository": "https://github.com/kevily/create-packer",
6
6
  "author": "1k <bug_zero@163.com>",
@@ -1,2 +1,2 @@
1
1
  export { default as routes } from './routes'
2
- export { default as names } from './names'
2
+ export { default as ids } from './ids'
@@ -1,11 +1,11 @@
1
1
  import { lazy } from 'react'
2
- import names from './names'
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
- name: names.home,
8
+ id: ids.home,
9
9
  Component: lazy(() => import('@/pages/home'))
10
10
  }
11
11
  ]
@@ -1,5 +1,5 @@
1
1
  import * as home from './home'
2
2
  export default {
3
3
  root: 'root',
4
- ...home.names
4
+ ...home.ids
5
5
  }
@@ -1,3 +1,3 @@
1
- export { default as routeNames } from './names'
1
+ export { default as ids } from './ids'
2
2
  export * from './router'
3
3
  export * from './router.provider'
@@ -1,22 +1,41 @@
1
1
  import { find, get } from 'lodash-es'
2
2
  import { stringify } from 'qs'
3
- import { NavigateOptions, redirect as routerRedirect } from 'react-router-dom'
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(name: string, path?: string | string[]) {
7
- const route = find(routesList, o => o.name === name)
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: { name: string; query?: Record<string, any> },
34
+ to: { id: routeType['id']; query?: Record<string, any> },
16
35
  opts?: NavigateOptions
17
36
  ) {
18
37
  return router.navigate(
19
- { pathname: getRoute(to.name, 'path'), search: to.query ? stringify(to.query) : '' },
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 * as home from './home'
5
- import names from './names'
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
- name: names.root,
10
+ id: ids.root,
12
11
  Component: lazy(() => import('@/layout')),
13
- children: [...home.routes]
12
+ children: []
14
13
  },
15
14
  {
16
15
  path: '*',
17
- name: '404',
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
- route.path = parentRoute
26
- ? `${parentRoute.path === '/' ? '' : parentRoute.path}/${route.path}`
27
- : route.path
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
+ })
@@ -1,6 +1,3 @@
1
1
  import { RouteObject } from 'react-router-dom'
2
2
 
3
- export type routeType = Omit<RouteObject, 'children'> & {
4
- name: string | symbol
5
- children?: routeType[]
6
- }
3
+ export type routeType = RouteObject