Expose framework routes for server-side matchRoutes usage #13288
jdnichollsc
started this conversation in
Proposals
Replies: 1 comment 1 reply
-
Hey folks, wondering if we can use the matchServerRoutes function from our SSR apps, can you share any example please? <3 Thanks for your support! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What version of React Router are you using?
7.4.0 (framework mode)
What problem are you trying to solve?
When using React Router in framework mode with
@react-router/express
and route modules defined inapp/routes.ts
(via@react-router/dev/routes
), there is no official way to access the resolved route objects on the server side to use with utilities likematchRoutes()
.The use case is to dynamically extract route patterns (e.g.,
/users/:id
) from the current URL on the server, to enhance tracing/logging systems (e.g., Datadog, OpenTelemetry) by setting tags likehttp.route
during server-side request handling.Describe the solution you'd like
I would like to have an official way to access the framework-generated routes in a format compatible with
matchRoutes()
on the server (e.g., a fully resolved array ofAgnosticRouteObject[]
or similar).This could be:
getResolvedRoutes()
that exposes the same route structure that is internally passed tocreateStaticRouter()
.RouteConfigEntry[]
from@react-router/dev/routes
into amatchRoutes()
-compatible structure.Why is this needed?
/dashboard/:id/settings
) in traces and logs.build.routes
and process it.matchRoutes()
on the backend.Describe alternatives you've considered
In older RemixJS-based setups, we used a manual workaround where we exported the route manifest and iterated over it on the server to match incoming requests:
https://github.com/brunojppb/react-router-datadog-express-tracing/blob/main/src/index.js#L114
However, this is less ergonomic now in React Router's framework mode since we already define routes in
app/routes.ts
using@react-router/dev/routes
, but there is no official utility to resolve them intoAgnosticRouteObject[]
.Additional context
@react-router/express
) to implement tracing/logging patterns without duplicating route definitions.Question
Is there a recommended approach or planned API to access resolved routes in framework mode for server-side use cases like this?
Thanks for your support! 🙌
Beta Was this translation helpful? Give feedback.
All reactions