-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into markdalgleish/support-create-remix-tags
- Loading branch information
Showing
73 changed files
with
785 additions
and
393 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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,87 @@ | ||
--- | ||
title: Breadcrumbs Guide | ||
--- | ||
|
||
# Breadcrumbs Guide | ||
|
||
In Remix, you can easily build dynamic breadcrumbs based on your route hierarchy. This guide will take you through the process using the `useMatches` and `handle` features. | ||
|
||
## Understanding the Basics | ||
|
||
Remix provides access to all route matches and related data at the top of the React element tree. This enables components like `<Meta />`, `<Links />`, and `<Scripts />` to obtain values from nested routes and render them at the top of the document. | ||
|
||
You can use a similar strategy using the `useMatches` and `handle` functions. While we're focusing on breadcrumbs, the principles demonstrated here are applicable to a range of scenarios. | ||
|
||
## Defining the Breadcrumbs for Routes | ||
|
||
Start by adding a `breadcrumb` attribute to your route's `handle`. This attribute isn't specific to Remix – you can name it whatever you like. For our example, we'll call it `breadcrumb`. | ||
|
||
```tsx filename=app/routes/parent.tsx | ||
export const handle = { | ||
breadcrumb: () => <Link to="/parent">Some Route</Link>, | ||
}; | ||
``` | ||
|
||
Similarly, you can define breadcrumbs for child routes: | ||
|
||
```tsx filename=app/routes/parent.child.tsx | ||
export const handle = { | ||
breadcrumb: () => ( | ||
<Link to="/parent/child">Child Route</Link> | ||
), | ||
}; | ||
``` | ||
|
||
## Aggregating Breadcrumbs in the Root Route | ||
|
||
Now, bring everything together in your root route using `useMatches`: | ||
|
||
```tsx filename=root.tsx lines=[5,9,19-28] | ||
import { | ||
Links, | ||
Scripts, | ||
useLoaderData, | ||
useMatches, | ||
} from "@remix-run/react"; | ||
|
||
export default function Root() { | ||
const matches = useMatches(); | ||
|
||
return ( | ||
<html lang="en"> | ||
<head> | ||
<Links /> | ||
</head> | ||
<body> | ||
<header> | ||
<ol> | ||
{matches | ||
.filter( | ||
(match) => | ||
match.handle && match.handle.breadcrumb | ||
) | ||
.map((match, index) => ( | ||
<li key={index}> | ||
{match.handle.breadcrumb(match)} | ||
</li> | ||
))} | ||
</ol> | ||
</header> | ||
<Outlet /> | ||
</body> | ||
</html> | ||
); | ||
} | ||
``` | ||
|
||
Note that we pass the `match` object to breadcrumbs, allowing us to potentially utilize `match.data` for enhancing breadcrumb content based on the route's data. This example doesn't use it, but you'll like want to use values from your loader data for the breadcrumb. | ||
|
||
Using `useMatches` with `handle` offers a robust way for routes to contribute to rendering processes higher up the element tree than their actual render point. | ||
|
||
## Additional Resources | ||
|
||
- [`useMatches`][use-matches] | ||
- [`handle`][handle] | ||
|
||
[use-matches]: ../hooks/use-matches | ||
[handle]: ../route/handle |
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
Oops, something went wrong.