How would one make a responsive master-detail view with createBrowserRouter? #11092
Replies: 2 comments 7 replies
-
You would likely need to think of the details view and list view as joint, and not as seperate. What I mean is, when you think about this as seperate views, DetailsView or ListView, Switch or rather For desktop, you need both components to render when you reach a url like
And you definitely can detect mobile vs desktop, so just consider picking a different layout based on that.
Skin it however you want. |
Beta Was this translation helpful? Give feedback.
-
I would avoid thinking of these as separate "routes"/"navigations" when on mobile versus desktop. Instead, they're the same route/navigation and you can use CSS to hide portions of the UX on certain displays const router = createBrowserRouter([{
path: "/",
Component: Root,
children: [{
path: "users",
Component: UsersList
children: [{
path: ":id",
Component: UserDetail
}],
}],
}]);
function UsersList() {
let outlet = useOutlet();
return (
<>
{/* hide the list portion of the UX when on mobile and we have an
outlet, indicating we're on the detail view */
<List className={outlet != null ? "hide-on-mobile-only" : ""} />
{/* UserDetail shows via the Outlet */}
{outlet}
</>
}
function UserDetail() {
return (
<>
{/* Provide a way to go back to the list view on mobile *}
<Link to=".." class="show-on-mobile-only" />
<div>
{/* User Details */}
</div>
</>
};
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
For context:
for example, I have a list of users and a detail view component. On mobile, when I click on a user in the list, i'd like to navigate to the detail page. When I'm on desktop, I'd like to have those two next to eachother.
I can only find examples of previous versions with the
Switch
component, but I don't know how this could be achieved in V6.Anyone that could help? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions