Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
remix-run-bot committed May 16, 2024
1 parent ef67804 commit 9d42655
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions docs/routers/create-browser-router.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ const routes = [
{
id: "parent",
path: "/parent",
loader({ request }, context) { /*...*/ },
loader({ request }, context) {
/*...*/
},
handle: {
async middleware({ request }, context) {
context.parent = "PARENT MIDDLEWARE";
Expand All @@ -285,7 +287,9 @@ const routes = [
{
id: "child",
path: "child",
loader({ request }, context) { /*...*/ },
loader({ request }, context) {
/*...*/
},
handle: {
async middleware({ request }, context) {
context.child = "CHILD MIDDLEWARE";
Expand All @@ -297,12 +301,19 @@ const routes = [
];

let router = createBrowserRouter(routes, {
async unstable_dataStrategy({ request, params, matches }) {
async unstable_dataStrategy({
request,
params,
matches,
}) {
// Run middleware sequentially and let them add data to `context`
let context = {};
for (const match of matches) {
if (match.route.handle?.middleware) {
await match.route.handle.middleware({ request, params }, context);
await match.route.handle.middleware(
{ request, params },
context
);
}
}

Expand Down

0 comments on commit 9d42655

Please sign in to comment.