File tree Expand file tree Collapse file tree
remix-app-for-testing/app/routes Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { useGetSocket } from "../hooks/useGetSocket";
66import { Tag } from "../components/Tag" ;
77import { VsCodeButton } from "../components/VScodeButton" ;
88import { useMemo } from "react" ;
9+ import { isLayoutRoute } from "../utils/misc" ;
910
1011export const ROUTE_COLORS : Record < string , string > = {
1112 ROUTE : "rdt-bg-green-500 rdt-text-white" ,
@@ -67,12 +68,9 @@ const PageTab = () => {
6768 const originalData = getOriginalData ( route . data ) ;
6869
6970 const isRoot = route . id === "root" ;
70- const lastPart = route . id . split ( "/" ) . pop ( ) ;
71- const isLayout =
72- lastPart ?. split ( "." ) ?. length === 1 &&
73- ( lastPart ?. startsWith ( "_" ) || lastPart ?. startsWith ( "__" ) ) &&
74- lastPart !== "_index" &&
75- "index" ;
71+
72+ const entryRoute = __remixManifest . routes [ route . id ] ;
73+ const isLayout = isLayoutRoute ( entryRoute ) ;
7674
7775 return (
7876 < li key = { route . id } className = "rdt-mb-8 rdt-ml-8" >
Original file line number Diff line number Diff line change @@ -13,16 +13,7 @@ import { useRDTContext } from "../context/useRDTContext";
1313import { Input } from "../components/Input" ;
1414import { NewRouteForm } from "../components/NewRouteForm" ;
1515import { useGetSocket } from "../hooks/useGetSocket" ;
16-
17- const isLayout = ( route : EntryRoute & { route : string } ) => {
18- const rId = route . id . replace ( "routes/" , "" ) ;
19- const v2Layout =
20- rId . startsWith ( "_" ) &&
21- ! rId . split ( "." ) [ 0 ] . endsWith ( "index" ) &&
22- rId . split ( "." ) . length === 1 ;
23- const v1Layout = rId . startsWith ( "__" ) ;
24- return v1Layout || v2Layout ;
25- } ;
16+ import { isLeafRoute } from "../utils/misc" ;
2617
2718const RoutesTab = ( ) => {
2819 const { routeWildcards, setRouteWildcards } = useRDTContext ( ) ;
@@ -35,7 +26,7 @@ const RoutesTab = () => {
3526 route : convertRemixPathToUrl ( window . __remixManifest . routes , route ) ,
3627 } ;
3728 } )
38- . filter ( ( route ) => ! isLayout ( route ) && route . id !== "root" )
29+ . filter ( ( route ) => isLeafRoute ( route ) )
3930 ) ;
4031 const navigate = useNavigate ( ) ;
4132
Original file line number Diff line number Diff line change 1+ import { EntryRoute } from "@remix-run/react/dist/routes" ;
2+
3+ type RouteType = "ROOT" | "LAYOUT" | "ROUTE" ;
4+
5+ export function getRouteType ( route : EntryRoute ) {
6+ let routeType : RouteType = "ROUTE" ;
7+
8+ if ( route . id === "root" ) {
9+ routeType = "ROOT" ;
10+ } else if ( route . index ) {
11+ routeType = "ROUTE" ;
12+ } else if ( ! route . path ) {
13+ // Pathless layout route
14+ routeType = "LAYOUT" ;
15+ } else {
16+ // Find an index route with parentId set to this route
17+ const childIndexRoute = Object . values ( window . __remixManifest . routes ) . find (
18+ ( r ) => r . parentId === route . id && r . index
19+ ) ;
20+
21+ routeType = childIndexRoute ? "LAYOUT" : "ROUTE" ;
22+ }
23+
24+ return routeType ;
25+ }
26+
27+ export function isLayoutRoute ( route : EntryRoute ) {
28+ return getRouteType ( route ) === "LAYOUT" ;
29+ }
30+
31+ export function isLeafRoute ( route : EntryRoute ) {
32+ return getRouteType ( route ) === "ROUTE" ;
33+ }
Original file line number Diff line number Diff line change 1+ export default function OtherIndexRoute ( ) {
2+ return < div > Other Home</ div >
3+ }
Original file line number Diff line number Diff line change 1+ export default function OtherPageRoute ( ) {
2+ return < div > Other Page</ div >
3+ }
Original file line number Diff line number Diff line change 1+ import { Outlet } from "@remix-run/react" ;
2+
3+ export default function OtherLayout ( ) {
4+ return < div >
5+ < h2 > Other Layout</ h2 >
6+ < Outlet />
7+ </ div >
8+ }
You can’t perform that action at this time.
0 commit comments