File tree Expand file tree Collapse file tree 3 files changed +6
-4
lines changed
Expand file tree Collapse file tree 3 files changed +6
-4
lines changed Original file line number Diff line number Diff line change 1+ // src/App.tsx
12import { Route , Routes } from "react-router-dom" ;
23import React from "react" ;
34
45// サブディレクトリを含む動的インポート
5- const pages = import . meta. glob ( './routes/**/* .tsx' ) ;
6+ const pages = import . meta. glob ( './routes/**/page .tsx' ) ;
67const layouts = import . meta. glob ( './routes/**/Layout.tsx' , { eager : true } ) ;
78
89const 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を探す
File renamed without changes.
Original file line number Diff line number Diff line change 11import React from "react" ;
22import { 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 ;
You can’t perform that action at this time.
0 commit comments