Skip to content

Commit 6ea92c6

Browse files
author
taku10101
committed
update: ()ルーティング無視
1 parent c747d76 commit 6ea92c6

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// src/App.tsx
12
import { Route, Routes } from "react-router-dom";
23
import React from "react";
34

45
// サブディレクトリを含む動的インポート
5-
const pages = import.meta.glob('./routes/**/*.tsx');
6+
const pages = import.meta.glob('./routes/**/page.tsx');
67
const layouts = import.meta.glob('./routes/**/Layout.tsx', { eager: true });
78

89
const App: React.FC = () => {
@@ -12,8 +13,9 @@ const App: React.FC = () => {
1213
const Component = React.lazy(pages[path] as () => Promise<{ default: React.ComponentType<any> }>);
1314
const routePath = path
1415
.replace('./routes', '')
15-
.replace('.tsx', '')
16+
.replace('/page.tsx', '')
1617
.replace(/\[([^\]]+)\]/g, ':$1')
18+
.replace(/\(([^)]+)\)/g, '') // ()で囲まれた部分を削除
1719
.toLowerCase(); // ルートパスを小文字に変換
1820

1921
// 最も近いLayoutを探す
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
22
import { useParams } from "react-router-dom";
33

4-
const DynamicPage: React.FC = () => {
4+
const Page = () => {
55
const { id } = useParams<{ id: string }>();
66

77
return <div>Dynamic Page for ID: {id}</div>;
88
};
99

10-
export default DynamicPage;
10+
export default Page;

0 commit comments

Comments
 (0)