Skip to content

Commit fa0ae0a

Browse files
authoredMar 3, 2025
Merge pull request #40 from rasengan-dev/fix/routing-system
fix: fix import routers into another router
2 parents 0e91593 + 7b4010a commit fa0ae0a

File tree

16 files changed

+103
-19
lines changed

16 files changed

+103
-19
lines changed
 

‎packages/create-rasengan/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unreleased
22

3+
## 1.2.0-beta.3 (2025-02-28)
4+
5+
## 1.2.0-beta.2 (2025-02-28)
6+
37
## 1.2.0-beta.1 (2025-02-28)
48

59
## 1.2.0-beta.0 (2025-02-25)

‎packages/create-rasengan/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-rasengan",
3-
"version": "1.2.0-beta.1",
3+
"version": "1.2.0-beta.3",
44
"description": "The Rasengan.js CLI tool to generate a new project with a simple template",
55
"main": "/dist/main.js",
66
"type": "module",

‎packages/create-rasengan/src/constants/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const Versions: {
2626
beta: string;
2727
} = {
2828
stable: null,
29-
beta: '1.0.0-beta.53',
29+
beta: '1.0.0-beta.55',
3030
};
3131

3232
/**

‎packages/rasengan/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
## Unreleased
2+
3+
## 1.0.0-beta.55 (2025-02-28)
4+
5+
## 1.0.0-beta.54 (2025-02-28)
6+
7+
## 1.0.0-beta.53 (2025-02-28)
8+
9+
## 1.0.0-beta.53 (2025-02-28)

‎packages/rasengan/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rasengan",
33
"private": false,
4-
"version": "1.0.0-beta.52",
4+
"version": "1.0.0-beta.55",
55
"description": "The modern React Framework",
66
"type": "module",
77
"main": "lib/esm/index.js",
@@ -80,14 +80,14 @@
8080
"react-router": "^7.0.0"
8181
},
8282
"peerDependencies": {
83+
"@rasenganjs/mdx": "workspace:^",
8384
"@types/node": "^18.0.0 || >=20.0.0",
8485
"less": "*",
8586
"react": "^19.0.0",
8687
"react-dom": "^19.0.0",
8788
"sass": "*",
8889
"stylus": "*",
89-
"vite": "^6.0.0",
90-
"@rasenganjs/mdx": "workspace:^"
90+
"vite": "^6.0.0"
9191
},
9292
"peerDependenciesMeta": {
9393
"@types/node": {

‎packages/rasengan/src/routing/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export type RouterProps = {
7171
/**
7272
* Usefull to collect sub routers
7373
*/
74-
imports?: Array<RouterComponent>;
74+
imports?: Array<Promise<RouterComponent>>;
7575

7676
/**
7777
* Usefull to define a layout

‎packages/rasengan/src/routing/utils/define-router.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ export const defineRouter = (option: RouterProps) => {
6363
}
6464
}
6565

66+
let routers = await Promise.all(imports ?? []);
67+
6668
// Set properties
67-
router.routers = imports || [];
69+
router.routers = routers;
6870
router.layout = layout || DefaultLayout;
6971
router.pages = pageComponentList;
7072
router.loaderComponent = loaderComponent || (() => null);

‎packages/rasengan/src/routing/utils/generate-routes.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export const generateRoutes = (
208208
const route: RouteObject = {
209209
path: !isRoot
210210
? router.useParentLayout
211-
? parentLayout.path + Layout.path
211+
? parentLayout.path + (Layout.path === '/' ? '' : Layout.path)
212212
: Layout.path
213213
: Layout.path,
214214
errorElement: <ErrorBoundary />,
@@ -310,17 +310,17 @@ export const generateRoutes = (
310310
route.children.push(page);
311311
});
312312

313-
// Loop through imported routers in order to apply the same thing.
313+
// Loop through imported routers in order to apply the same logic like above.
314314
for (const importedRouter of router.routers) {
315315
const importedRoutes = generateRoutes(importedRouter, false, Layout);
316316

317-
importedRoutes.forEach((route) => {
318-
if (route.nested) {
319-
route.children.push(route);
317+
for (const importedRoute of importedRoutes) {
318+
if (importedRoute.nested) {
319+
route.children.push(importedRoute);
320320
} else {
321-
routes.push(route);
321+
routes.push(importedRoute);
322322
}
323-
});
323+
}
324324
}
325325

326326
// Make sure to add the route at the beginning of the list

‎packages/rasengan/src/server/dev/server.ts

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ async function devRequestHandler(
5252
// Get static routes
5353
const staticRoutes = generateRoutes(AppRouter);
5454

55+
console.log({ staticRoutes: JSON.stringify(staticRoutes) });
56+
5557
// Create static handler
5658
let handler = createStaticHandler(staticRoutes);
5759

‎playground/rasengan-v1-test/src/app/app.router.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { RouterComponent, defineRouter } from 'rasengan';
22
import AppLayout from '@/app/app.layout';
33
import Home from '@/app/home.page';
44
import Blog from '@/app/blog.page.mdx';
5+
import SubRouter from '@/app/sub-router/sub-router.router';
56

67
class AppRouter extends RouterComponent {}
78

89
export default defineRouter({
9-
imports: [],
10+
imports: [SubRouter],
1011
layout: AppLayout,
1112
pages: [Home, Blog],
1213
})(AppRouter);

‎playground/rasengan-v1-test/src/app/home.page.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const Home: PageComponent = (props: any) => {
2727
</div>
2828

2929
<div className="mt-8 flex flex-wrap justify-center gap-4">
30-
<div className="flex flex-col p-4 rounded-md border-[1px] border-[EFEFEF] max-w-[500px] md:w-[300px] lg:w-[400px]">
30+
<div className="flex flex-col p-4 rounded-md border-[1px] border-[#EFEFEF] max-w-[500px] md:w-[300px] lg:w-[400px]">
3131
<h2 className="text-xl font-urbanist">Documentation</h2>
3232
<p className="mt-2">
3333
Find in-depth information about Rasengan features and API.
@@ -41,7 +41,7 @@ const Home: PageComponent = (props: any) => {
4141
</a>
4242
</div>
4343

44-
<div className="flex flex-col p-4 rounded-md border-[1px] border-[EFEFEF] max-w-[500px] md:w-[300px] lg:w-[400px]">
44+
<div className="flex flex-col p-4 rounded-md border-[1px] border-[#EFEFEF] max-w-[500px] md:w-[300px] lg:w-[400px]">
4545
<h2 className="text-xl font-urbanist">Learn</h2>
4646
<p className="mt-2">
4747
Learn about Rasengan in an interactive course with quizzes!
@@ -55,7 +55,7 @@ const Home: PageComponent = (props: any) => {
5555
</a>
5656
</div>
5757

58-
<div className="flex flex-col p-4 rounded-md border-[1px] border-[EFEFEF] max-w-[500px] md:w-[300px] lg:w-[400px]">
58+
<div className="flex flex-col p-4 rounded-md border-[1px] border-[#EFEFEF] max-w-[500px] md:w-[300px] lg:w-[400px]">
5959
<h2 className="text-xl font-urbanist">Examples</h2>
6060
<p className="mt-2">
6161
Discover and deploy boilerplate example Rasengan projects.
@@ -69,7 +69,7 @@ const Home: PageComponent = (props: any) => {
6969
</a>
7070
</div>
7171

72-
<div className="flex flex-col p-4 rounded-md border-[1px] border-[EFEFEF] max-w-[500px] md:w-[300px] lg:w-[400px]">
72+
<div className="flex flex-col p-4 rounded-md border-[1px] border-[#EFEFEF] max-w-[500px] md:w-[300px] lg:w-[400px]">
7373
<h2 className="text-xl font-urbanist">Community</h2>
7474
<p className="mt-2">
7575
Join an active community of Rasengan users on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { PageComponent } from 'rasengan';
2+
3+
export const About: PageComponent = () => {
4+
return (
5+
<section>
6+
<h1>About page</h1>
7+
</section>
8+
);
9+
};
10+
11+
About.path = '/about';
12+
13+
About.metadata = {
14+
title: 'About',
15+
description: 'About page',
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { PageComponent } from 'rasengan';
2+
3+
export const Contact: PageComponent = () => {
4+
return (
5+
<section>
6+
<h1>Contact page</h1>
7+
</section>
8+
);
9+
};
10+
11+
Contact.path = '/contact';
12+
13+
Contact.metadata = {
14+
title: 'Contact',
15+
description: 'Contact page',
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineRoutesGroup } from 'rasengan';
2+
import { Contact } from './contact.page';
3+
import { Pricing } from './pricing.page';
4+
5+
export default defineRoutesGroup({
6+
path: '/group',
7+
children: [Contact, Pricing],
8+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { PageComponent } from 'rasengan';
2+
3+
export const Pricing: PageComponent = () => {
4+
return (
5+
<section>
6+
<h1>Pricing page</h1>
7+
</section>
8+
);
9+
};
10+
11+
Pricing.path = '/pricing';
12+
13+
Pricing.metadata = {
14+
title: 'Pricing',
15+
description: 'Pricing page',
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineRouter, RouterComponent } from 'rasengan';
2+
import { About } from '@/app/sub-router/about.page';
3+
import Group1 from './group/index.group';
4+
5+
class SubRouter extends RouterComponent {}
6+
7+
export default defineRouter({
8+
imports: [],
9+
pages: [About, Group1],
10+
// useParentLayout: false
11+
})(SubRouter);

0 commit comments

Comments
 (0)
Please sign in to comment.