AniUI Academy

React Router has 3 modes. Which one does your app need?

React Router offers Declarative, Data, and Framework modes; understanding what each handles makes it easier to choose a setup that fits your application.

Anish Lawrence3 min read

You open React Router’s documentation and find three starting points: Declarative, Data, and Framework. If you remember wrapping your app in BrowserRouter, you might wonder whether that approach has been replaced.

It remains supported. The choice is about how much work you want React Router to handle.

Declarative is familiar

Declarative Mode connects URLs to components and helps users navigate. It is the familiar BrowserRouter approach, rather than a new invention.

You describe routes using Routes and Route. Link lets users move between pages, while NavLink can indicate which page is active.

Imagine a small shop with a homepage, product list, and product details page. Declarative Mode can handle navigation between those screens.

It also supports nested routes and shared layouts. You can keep the shop’s navigation visible while the page content changes underneath it.

This approach can fit an application that already has a way to manage data. The router handles navigation while your existing code handles fetching, loading, and updates.

Data adds coordination

Data Mode adds route-based data loading, actions, and pending states, so the router can coordinate more of the page’s behavior.

A typical browser setup uses createBrowserRouter and RouterProvider. Routes can define loaders that provide data before their components render.

For the shop, a product route could load the selected product. An action could handle a form submission, with the application using the router’s data features to update what appears afterward.

The useful question is whether loading and submissions belong alongside your route definitions.

If you are repeatedly connecting navigation, requests, and loading indicators yourself, Data Mode gives you another way to organize that work. You still need to decide what the user sees while waiting and when a request fails.

Framework adds tooling

Framework Mode builds on Data Mode with a Vite plugin, route type generation, automatic code splitting, and rendering options.

For the shop, that means React Router takes responsibility for more of the application setup. Its conventions help connect route files, data, and the build process.

Framework Mode supports single-page applications, server rendering, and static rendering. Choosing it does not automatically mean every page must render on a server.

The trade-off is adopting more of the framework’s structure. That can reduce decisions you would otherwise make yourself, but it also gives the team conventions to learn.

Consider it when you want an integrated starting point rather than assembling routing and application tooling separately.

Avoid the syntax trap

Writing routes in JSX does not, by itself, tell you which mode an application uses. Check the top-level router setup.

BrowserRouter points to Declarative Mode. A data router connected through RouterProvider points to Data Mode. The React Router Vite plugin is part of Framework Mode.

This distinction helps when following tutorials or asking AI for code. A valid example for another mode may use features your current setup does not provide.

Before copying a loader or form example, check its mode and your installed version.

Also avoid treating the three choices as beginner, intermediate, and expert levels. An experienced team can deliberately choose a smaller routing setup because the rest of its architecture already works.

Choose by responsibility

Pick the mode that fits how your application handles navigation, data, and tooling. More built-in features are useful when you need them.

Start with three questions. Do you already have a data layer you want to keep? Would route-based loading and submissions simplify the code? Do you want a framework to organize the application build?

Discuss those answers using one real feature, such as opening a product and submitting an enquiry. That makes the choice easier to assess than comparing feature lists alone.

My take: you do not need to migrate a working application just because the documentation offers more options. Understand what each mode takes responsibility for, then choose the arrangement your team can explain and maintain.

Thanks for reading. #React #ReactRouter #FrontendDevelopment #WebDevelopment

Related reading

Discussion

Sign in to post
Sign in to join the conversation.Sign in

No comments yet. Be the first to say something.