@samadhi1311/router 1.0.1 → 1.0.3

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
@@ -100,7 +100,7 @@ function router(options = {}) {
100
100
  return routes;
101
101
  }
102
102
  function generateRouteCode(routes) {
103
- let imports = 'import { createElement, Suspense } from "react";\nimport { Outlet } from "react-router";\n';
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) {
@@ -114,15 +114,15 @@ function router(options = {}) {
114
114
  `;
115
115
  }
116
116
  if (layoutId && route.layoutPath) {
117
- imports += `import ${layoutId} from '${resolveFile(route.componentPath)}';
117
+ imports += `import ${layoutId} from '${resolveFile(route.layoutPath)}';
118
118
  `;
119
119
  }
120
120
  if (loadingId && route.loadingPath) {
121
- imports += `import ${loadingId} from '${resolveFile(route.componentPath)}';
121
+ imports += `import ${loadingId} from '${resolveFile(route.loadingPath)}';
122
122
  `;
123
123
  }
124
124
  if (notFoundId && route.notFoundPath) {
125
- imports += `import ${notFoundId} from ''${resolveFile(route.componentPath)}';
125
+ imports += `import ${notFoundId} from '${resolveFile(route.notFoundPath)}';
126
126
  `;
127
127
  }
128
128
  let config = `${indent}{
@@ -130,18 +130,18 @@ function router(options = {}) {
130
130
  config += `${indent} path: '${route.path}',
131
131
  `;
132
132
  if (layoutId) {
133
- config += `${indent} element: createElement(${layoutId}, null, createElement(Outlet)),
133
+ config += `${indent} element: <${layoutId}><Outlet /></${layoutId}>,
134
134
  `;
135
135
  } else if (componentId) {
136
- const element = loadingId ? `createElement(Suspense, { fallback: createElement(${loadingId}) }, createElement(${componentId}))` : `createElement(${componentId})`;
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: createElement(Outlet),
140
+ config += `${indent} element: <Outlet />,
141
141
  `;
142
142
  }
143
143
  if (notFoundId) {
144
- config += `${indent} errorElement: createElement(${notFoundId}),
144
+ config += `${indent} errorElement: <${notFoundId} />,
145
145
  `;
146
146
  }
147
147
  if (route.children && route.children.length > 0) {
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 { createElement, Suspense } from "react";\nimport { Outlet } from "react-router";\n';
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) {
@@ -80,15 +80,15 @@ function router(options = {}) {
80
80
  `;
81
81
  }
82
82
  if (layoutId && route.layoutPath) {
83
- imports += `import ${layoutId} from '${resolveFile(route.componentPath)}';
83
+ imports += `import ${layoutId} from '${resolveFile(route.layoutPath)}';
84
84
  `;
85
85
  }
86
86
  if (loadingId && route.loadingPath) {
87
- imports += `import ${loadingId} from '${resolveFile(route.componentPath)}';
87
+ imports += `import ${loadingId} from '${resolveFile(route.loadingPath)}';
88
88
  `;
89
89
  }
90
90
  if (notFoundId && route.notFoundPath) {
91
- imports += `import ${notFoundId} from ''${resolveFile(route.componentPath)}';
91
+ imports += `import ${notFoundId} from '${resolveFile(route.notFoundPath)}';
92
92
  `;
93
93
  }
94
94
  let config = `${indent}{
@@ -96,18 +96,18 @@ function router(options = {}) {
96
96
  config += `${indent} path: '${route.path}',
97
97
  `;
98
98
  if (layoutId) {
99
- config += `${indent} element: createElement(${layoutId}, null, createElement(Outlet)),
99
+ config += `${indent} element: <${layoutId}><Outlet /></${layoutId}>,
100
100
  `;
101
101
  } else if (componentId) {
102
- const element = loadingId ? `createElement(Suspense, { fallback: createElement(${loadingId}) }, createElement(${componentId}))` : `createElement(${componentId})`;
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: createElement(Outlet),
106
+ config += `${indent} element: <Outlet />,
107
107
  `;
108
108
  }
109
109
  if (notFoundId) {
110
- config += `${indent} errorElement: createElement(${notFoundId}),
110
+ config += `${indent} errorElement: <${notFoundId} />,
111
111
  `;
112
112
  }
113
113
  if (route.children && route.children.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samadhi1311/router",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A simple router for Vite inspired by Next.JS App Router",
5
5
  "author": {
6
6
  "name": "Samadhi Gunasinghe",