@samadhi1311/router 1.0.2 → 1.0.4
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/dist/index.cjs +9 -6
- package/dist/index.js +9 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -100,7 +100,7 @@ function router(options = {}) {
|
|
|
100
100
|
return routes;
|
|
101
101
|
}
|
|
102
102
|
function generateRouteCode(routes) {
|
|
103
|
-
let imports = 'import {
|
|
103
|
+
let imports = 'import { Suspense } from "react";\nimport { Outlet } from "react-router";\n';
|
|
104
104
|
let routeConfigs = "";
|
|
105
105
|
let importCounter = 0;
|
|
106
106
|
function processRoute(route, depth = 0) {
|
|
@@ -130,18 +130,18 @@ function router(options = {}) {
|
|
|
130
130
|
config += `${indent} path: '${route.path}',
|
|
131
131
|
`;
|
|
132
132
|
if (layoutId) {
|
|
133
|
-
config += `${indent} element:
|
|
133
|
+
config += `${indent} element: <${layoutId}><Outlet /></${layoutId}>,
|
|
134
134
|
`;
|
|
135
135
|
} else if (componentId) {
|
|
136
|
-
const element = loadingId ?
|
|
136
|
+
const element = loadingId ? `<Suspense fallback={<${loadingId} />}><${componentId} /></Suspense>` : `<${componentId} />`;
|
|
137
137
|
config += `${indent} element: ${element},
|
|
138
138
|
`;
|
|
139
139
|
} else {
|
|
140
|
-
config += `${indent} element:
|
|
140
|
+
config += `${indent} element: <Outlet />,
|
|
141
141
|
`;
|
|
142
142
|
}
|
|
143
143
|
if (notFoundId) {
|
|
144
|
-
config += `${indent} errorElement:
|
|
144
|
+
config += `${indent} errorElement: <${notFoundId} />,
|
|
145
145
|
`;
|
|
146
146
|
}
|
|
147
147
|
if (route.children && route.children.length > 0) {
|
|
@@ -179,7 +179,10 @@ ${routeConfigs}];
|
|
|
179
179
|
load(id) {
|
|
180
180
|
if (id === resolvedVirtualModuleId) {
|
|
181
181
|
const routes = scanDirectory("");
|
|
182
|
-
return
|
|
182
|
+
return {
|
|
183
|
+
code: generateRouteCode(routes),
|
|
184
|
+
lang: "tsx"
|
|
185
|
+
};
|
|
183
186
|
}
|
|
184
187
|
},
|
|
185
188
|
handleHotUpdate({ file, server }) {
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ function router(options = {}) {
|
|
|
66
66
|
return routes;
|
|
67
67
|
}
|
|
68
68
|
function generateRouteCode(routes) {
|
|
69
|
-
let imports = 'import {
|
|
69
|
+
let imports = 'import { Suspense } from "react";\nimport { Outlet } from "react-router";\n';
|
|
70
70
|
let routeConfigs = "";
|
|
71
71
|
let importCounter = 0;
|
|
72
72
|
function processRoute(route, depth = 0) {
|
|
@@ -96,18 +96,18 @@ function router(options = {}) {
|
|
|
96
96
|
config += `${indent} path: '${route.path}',
|
|
97
97
|
`;
|
|
98
98
|
if (layoutId) {
|
|
99
|
-
config += `${indent} element:
|
|
99
|
+
config += `${indent} element: <${layoutId}><Outlet /></${layoutId}>,
|
|
100
100
|
`;
|
|
101
101
|
} else if (componentId) {
|
|
102
|
-
const element = loadingId ?
|
|
102
|
+
const element = loadingId ? `<Suspense fallback={<${loadingId} />}><${componentId} /></Suspense>` : `<${componentId} />`;
|
|
103
103
|
config += `${indent} element: ${element},
|
|
104
104
|
`;
|
|
105
105
|
} else {
|
|
106
|
-
config += `${indent} element:
|
|
106
|
+
config += `${indent} element: <Outlet />,
|
|
107
107
|
`;
|
|
108
108
|
}
|
|
109
109
|
if (notFoundId) {
|
|
110
|
-
config += `${indent} errorElement:
|
|
110
|
+
config += `${indent} errorElement: <${notFoundId} />,
|
|
111
111
|
`;
|
|
112
112
|
}
|
|
113
113
|
if (route.children && route.children.length > 0) {
|
|
@@ -145,7 +145,10 @@ ${routeConfigs}];
|
|
|
145
145
|
load(id) {
|
|
146
146
|
if (id === resolvedVirtualModuleId) {
|
|
147
147
|
const routes = scanDirectory("");
|
|
148
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
code: generateRouteCode(routes),
|
|
150
|
+
lang: "tsx"
|
|
151
|
+
};
|
|
149
152
|
}
|
|
150
153
|
},
|
|
151
154
|
handleHotUpdate({ file, server }) {
|