Closed giopetris closed 1 year ago
It will work, but, depending on how routes are used on the backend, it might be inconvenient, because the API is designed for React Router. If you need something more generic, I recommend Typesafe Routes.
If the API is suitable for your use case, there aren't really any other concerns. Hooks aside, only two functions from React Router are used: createSearchParams
and generatePath
.
In fact, you can even use the library without any peer dependencies, if you use the root entry point. Hooks aside, the API is the same, but, instead of route
, you get createRoute
, and you can construct route
yourself:
import { createRoute } from "react-router-typesafe-routes";
import { createSearchParams, generatePath } from "./custom-implementation";
const route = createRoute({ createSearchParams, generatePath });
It's not documented, but it's technically a part of public API.
WARNING: For demonstration purposes only, I don't think it makes practical sense to do this.
Thanks so much @fenok !
My current setup is a monorepo where the URLs are shared between frontend app (using react-router) and a backend app (using node), my concern is that since this relies on
react-router
it will not work on the backend app, or am I missing something?