Replies: 4 comments 6 replies
-
I think you can use any routing mode that suits your project. Library ModeThis is for when you want to use react router in another project that already has a react setup, this can be a vite project for example. So use library mode if you have or want to use vite. If you are not interested in using vite and you want to just use react router, then you can use the framework mode. Framework ModeThe framework mode should support all the routing features you will get from the library mode. Only that you declare routes a bit more differently. There are over 3 ways I know of and you can see information about them below. Route ConfigYou can use the route config to configure your routes. You can find the information here, Routing. It discusses how to use the route config to configure your routes. It supports layouts, nested routes, route prefixes, loaders,actions and other features you can check out in the document. File based RoutingFile based routing allows you to configure your routes using files as your routes like you have in remix or nextjs. Follow this documentation for how to set this up with react router (https://reactrouter.com/how-to/file-route-conventions). You will have to update your routes config file with the fs routes package and then follow the document on how to write your file based routes. This also supports layouts, nested routes, route prefixes , loaders, actions and other router features. Component RoutesNow, component routes in the react router framework is not exactly a routing strategy for your whole application. It just allows you to render a page and then have a section of it render different components based on the url. It does not support the full react router route module features like data loading, actions... It's to be used when you just want to render a different react component on the page based on the url. But they can of course use any feature in react router that a normal component can use like Whether you are using the library mode or framework mode with file based routing or route configuration, they all allow you to use the react router route modules, so you have access to all features such as actions, loaders, ErrorBoundary, links, meta... |
Beta Was this translation helpful? Give feedback.
-
Hello there, I'm also confused. |
Beta Was this translation helpful? Give feedback.
-
Why does the Framework Installation page not include instructions for enabling it in an existing project? It just says "You can view the template on GitHub to see how to manually set up your project." That's not particularly helpful. There's even already instructions for how to set it up in the "Framework Adoption from RouterProvider/Component Routes" sections, they just assume you've already got a Library installation set up. |
Beta Was this translation helpful? Give feedback.
-
Yes, Me too wondering. Should I use library or framework in the future? |
Beta Was this translation helpful? Give feedback.
-
Hi there, I was going through the v7 docs and notice that v7 marks the boundary between library mode and framework mode.
Most of us most likely would have existing projects scaffolded from vite command, does that mean we need to create a new project via react-router cli in order to opt into framework mode?
I notice framework mode is packed with a lot more features than library mode, however the v6 way of declaring routes has also changed? e.g
and v7 docs suggest to declare routes via Route Components?
Can someone please explain to me whats going on and which mode we should be going for if existing projects?
thanks
Beta Was this translation helpful? Give feedback.
All reactions