-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add nested routes sample. * Fix identifying layout routes. * fix: don't relay on route ordering, that index route comes first.
- Loading branch information
Showing
6 changed files
with
53 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { EntryRoute } from "@remix-run/react/dist/routes"; | ||
|
||
type RouteType = "ROOT" | "LAYOUT" | "ROUTE"; | ||
|
||
export function getRouteType(route: EntryRoute) { | ||
let routeType: RouteType = "ROUTE"; | ||
|
||
if (route.id === "root") { | ||
routeType = "ROOT"; | ||
} else if (route.index) { | ||
routeType = "ROUTE"; | ||
} else if (!route.path) { | ||
// Pathless layout route | ||
routeType = "LAYOUT"; | ||
} else { | ||
// Find an index route with parentId set to this route | ||
const childIndexRoute = Object.values(window.__remixManifest.routes).find( | ||
(r) => r.parentId === route.id && r.index | ||
); | ||
|
||
routeType = childIndexRoute ? "LAYOUT" : "ROUTE"; | ||
} | ||
|
||
return routeType; | ||
} | ||
|
||
export function isLayoutRoute(route: EntryRoute) { | ||
return getRouteType(route) === "LAYOUT"; | ||
} | ||
|
||
export function isLeafRoute(route: EntryRoute) { | ||
return getRouteType(route) === "ROUTE"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function OtherIndexRoute() { | ||
return <div>Other Home</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function OtherPageRoute() { | ||
return <div>Other Page</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Outlet } from "@remix-run/react"; | ||
|
||
export default function OtherLayout() { | ||
return <div> | ||
<h2>Other Layout</h2> | ||
<Outlet /> | ||
</div> | ||
} |