Skip to content

Is it possible to split routing into multiple files with the new data APIs? #10160

Closed Answered by dead1ock
WonkiestNebula asked this question in Q&A
Discussion options

You must be logged in to vote

I haven't found a way to do this using createRoutesFromElements() without an error about duplicate routeIds. This is how I approached splitting up Routes using module exports.

// src/App.tsx
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import AppRoutes from 'routes';

const router = createBrowserRouter(AppRoutes);

export const App = () => {
  return (
      <RouterProvider router={router} />
  );
};
// src/routes/index.tsx

import AuthRoutes from './auth';
import ProfileRoute from './profile';

const AppRoutes = [
  {
    path: '/',
    element: <Root />
    children: [
      AuthRoutes,
      ProfileRoute,
      // etc...
    ]
];

export default AppRoutes;
//…

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
8 replies
@brophdawg11
Comment options

@jasikpark
Comment options

@jasikpark
Comment options

@jasikpark
Comment options

@AprilMay812
Comment options

Answer selected by WonkiestNebula
Comment options

You must be logged in to vote
1 reply
@jch422
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants