Skip to content

Instantly share code, notes, and snippets.

@itaditya
Created August 30, 2021 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itaditya/96819594ad3d7db37232027eca0a6aab to your computer and use it in GitHub Desktop.
Save itaditya/96819594ad3d7db37232027eca0a6aab to your computer and use it in GitHub Desktop.
Vite glob imports to React Router config
import convertToRoutes from 'your-awesome-oss-pkg';
const modules = {
'index.js': IndexComp,
'about.js': AboutComp,
'team.js': TeamComp,
'team/index.js': TeamIndexComp,
'team/join.js': TeamJoinComp,
'team/$username.js': TeamMemberComp,
};
// And when I run `const routes = convertToRoutes(modules)`
const routes = [
{ path: '/', element: <IndexComp /> },
{ path: 'about', element: <AboutComp /> },
{
path: 'team',
element: <TeamComp />,
children: [
{ path: '/', element: <TeamIndexComp /> },
{ path: 'join', element: <TeamJoinComp /> },
{ path: ':username', element: <TeamMemberComp /> },
],
},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment