@samadhi1311/router 1.0.5 → 1.0.6

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 CHANGED
@@ -101,29 +101,19 @@ function router(options = {}) {
101
101
  return routes;
102
102
  }
103
103
  function generateRouteCode(routes) {
104
- let imports = 'import { Suspense } from "react";\nimport { Outlet } from "react-router";\n';
104
+ let imports = 'import { Outlet, RouteObject } from "react-router-dom";\n';
105
105
  let routeConfigs = "";
106
106
  let importCounter = 0;
107
107
  function processRoute(route, depth = 0) {
108
108
  const indent = " ".repeat(depth + 1);
109
109
  const componentId = route.componentPath ? `Page${importCounter++}` : null;
110
110
  const layoutId = route.layoutPath ? `Layout${importCounter++}` : null;
111
- const loadingId = route.loadingPath ? `Loading${importCounter++}` : null;
112
- const notFoundId = route.notFoundPath ? `NotFound${importCounter++}` : null;
113
111
  if (componentId && route.componentPath) {
114
112
  imports += `import ${componentId} from '${resolveFile(route.componentPath)}';
115
113
  `;
116
114
  }
117
115
  if (layoutId && route.layoutPath) {
118
116
  imports += `import ${layoutId} from '${resolveFile(route.layoutPath)}';
119
- `;
120
- }
121
- if (loadingId && route.loadingPath) {
122
- imports += `import ${loadingId} from '${resolveFile(route.loadingPath)}';
123
- `;
124
- }
125
- if (notFoundId && route.notFoundPath) {
126
- imports += `import ${notFoundId} from '${resolveFile(route.notFoundPath)}';
127
117
  `;
128
118
  }
129
119
  let config = `${indent}{
@@ -131,18 +121,13 @@ function router(options = {}) {
131
121
  config += `${indent} path: '${route.path}',
132
122
  `;
133
123
  if (layoutId) {
134
- config += `${indent} element: <${layoutId}><Outlet /></${layoutId}>,
124
+ config += `${indent} element: ${layoutId},
135
125
  `;
136
126
  } else if (componentId) {
137
- const element = loadingId ? `<Suspense fallback={<${loadingId} />}><${componentId} /></Suspense>` : `<${componentId} />`;
138
- config += `${indent} element: ${element},
127
+ config += `${indent} element: ${componentId},
139
128
  `;
140
129
  } else {
141
- config += `${indent} element: <Outlet />,
142
- `;
143
- }
144
- if (notFoundId) {
145
- config += `${indent} errorElement: <${notFoundId} />,
130
+ config += `${indent} element: Outlet,
146
131
  `;
147
132
  }
148
133
  if (route.children && route.children.length > 0) {
@@ -162,7 +147,7 @@ function router(options = {}) {
162
147
  routeConfigs += processRoute(route, 0);
163
148
  });
164
149
  return `${imports}
165
- export const routes = [
150
+ export const routes: RouteObject[] = [
166
151
  ${routeConfigs}];
167
152
  `;
168
153
  }
package/dist/index.js CHANGED
@@ -67,29 +67,19 @@ function router(options = {}) {
67
67
  return routes;
68
68
  }
69
69
  function generateRouteCode(routes) {
70
- let imports = 'import { Suspense } from "react";\nimport { Outlet } from "react-router";\n';
70
+ let imports = 'import { Outlet, RouteObject } from "react-router-dom";\n';
71
71
  let routeConfigs = "";
72
72
  let importCounter = 0;
73
73
  function processRoute(route, depth = 0) {
74
74
  const indent = " ".repeat(depth + 1);
75
75
  const componentId = route.componentPath ? `Page${importCounter++}` : null;
76
76
  const layoutId = route.layoutPath ? `Layout${importCounter++}` : null;
77
- const loadingId = route.loadingPath ? `Loading${importCounter++}` : null;
78
- const notFoundId = route.notFoundPath ? `NotFound${importCounter++}` : null;
79
77
  if (componentId && route.componentPath) {
80
78
  imports += `import ${componentId} from '${resolveFile(route.componentPath)}';
81
79
  `;
82
80
  }
83
81
  if (layoutId && route.layoutPath) {
84
82
  imports += `import ${layoutId} from '${resolveFile(route.layoutPath)}';
85
- `;
86
- }
87
- if (loadingId && route.loadingPath) {
88
- imports += `import ${loadingId} from '${resolveFile(route.loadingPath)}';
89
- `;
90
- }
91
- if (notFoundId && route.notFoundPath) {
92
- imports += `import ${notFoundId} from '${resolveFile(route.notFoundPath)}';
93
83
  `;
94
84
  }
95
85
  let config = `${indent}{
@@ -97,18 +87,13 @@ function router(options = {}) {
97
87
  config += `${indent} path: '${route.path}',
98
88
  `;
99
89
  if (layoutId) {
100
- config += `${indent} element: <${layoutId}><Outlet /></${layoutId}>,
90
+ config += `${indent} element: ${layoutId},
101
91
  `;
102
92
  } else if (componentId) {
103
- const element = loadingId ? `<Suspense fallback={<${loadingId} />}><${componentId} /></Suspense>` : `<${componentId} />`;
104
- config += `${indent} element: ${element},
93
+ config += `${indent} element: ${componentId},
105
94
  `;
106
95
  } else {
107
- config += `${indent} element: <Outlet />,
108
- `;
109
- }
110
- if (notFoundId) {
111
- config += `${indent} errorElement: <${notFoundId} />,
96
+ config += `${indent} element: Outlet,
112
97
  `;
113
98
  }
114
99
  if (route.children && route.children.length > 0) {
@@ -128,7 +113,7 @@ function router(options = {}) {
128
113
  routeConfigs += processRoute(route, 0);
129
114
  });
130
115
  return `${imports}
131
- export const routes = [
116
+ export const routes: RouteObject[] = [
132
117
  ${routeConfigs}];
133
118
  `;
134
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samadhi1311/router",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "A simple router for Vite inspired by Next.JS App Router",
5
5
  "author": {
6
6
  "name": "Samadhi Gunasinghe",