Created
August 30, 2021 12:06
-
-
Save itaditya/96819594ad3d7db37232027eca0a6aab to your computer and use it in GitHub Desktop.
Vite glob imports to React Router config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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