Skip to content

Commit c747d76

Browse files
author
taku10101
committed
update: 多重構造 動的ルーティングの対応
1 parent c9c393a commit c747d76

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ const App: React.FC = () => {
1717
.toLowerCase(); // ルートパスを小文字に変換
1818

1919
// 最も近いLayoutを探す
20-
const layoutPath = Object.keys(layouts).find(layoutPath => path.startsWith(layoutPath.replace('/Layout.tsx', '')));
20+
const layoutPath = Object.keys(layouts).reduce((closest, layoutPath) => {
21+
if (path.startsWith(layoutPath.replace('/Layout.tsx', ''))) {
22+
return layoutPath.length > (closest?.length || 0) ? layoutPath : closest;
23+
}
24+
return closest;
25+
}, undefined as string | undefined);
26+
2127
const LayoutComponent = layoutPath ? (layouts[layoutPath] as { default: React.ComponentType<any> }).default : React.Fragment;
2228

2329
return (

0 commit comments

Comments
 (0)