Remix Flat Routes
This package enables you to define your routes using the flat-routes convention. This is based on the gist by Ryan Florence
π
Installation
> npm install remix-flat-routes
βοΈ
Configuration
Update your remix.config.js file and use the custom routes config option.
const { flatRoutes } = require('remix-flat-routes')
module.exports = {
// ignore all files in routes folder
ignoredRouteFiles: ['**/*'],
routes: async defineRoutes => {
return flatRoutes('routes', defineRoutes)
},
}
NOTE: basePath
should be relative to the app
folder. If you want to use the routes
folder, you will need to update the ignoreRouteFiles
property to ignore all files: **/*
π
Migrating Existing Routes
You can now migrate your existing routes to the new flat-routes convention. Simply run:
npx migrate-flat-routes <sourceDir> <targetDir> [options]
Example:
npx migrate-flat-routes ./app/routes ./app/flatroutes --convention=flat-folders
NOTE:
sourceDir and targetDir are relative to project root
Options:
--convention=<convention>
The convention to use when migrating.
flat-files - Migrates all files to a flat directory structure.
flat-folders - Migrates all files to a flat directory structure, but
creates folders for each route.
π¨
Flat Routes Convention
routes/
_auth.forgot-password.tsx
_auth.login.tsx
_auth.reset-password.tsx
_auth.signup.tsx
_auth.tsx
_landing.about.tsx
_landing.index.tsx
_landing.tsx
app.calendar.$day.tsx
app.calendar.index.tsx
app.calendar.tsx
app.projects.$id.tsx
app.projects.tsx
app.tsx
app_.projects.$id.roadmap.tsx
app_.projects.$id.roadmap[.pdf].tsx
As React Router routes:
} /><Routes> <Route element={<Auth />}> <Route path="forgot-password" element={<Forgot />} /> <Route path="login" element={<Login />} /> <Route path="reset-password" element={<Reset />} /> <Route path="signup" element={<Signup />} /> </Route> <Route element={<Landing />}> <Route path="about" element={<About />} /> <Route index element={<Index />} /> </Route> <Route path="app" element={<App />}> <Route path="calendar" element={<Calendar />}> <Route path=":day" element={<Day />} /> <Route index element={<CalendarIndex />} /> </Route> <Route path="projects" element={<Projects />}> <Route path=":id" element={<Project />} /> </Route> </Route> <Route path="app/projects/:id/roadmap" element={<Roadmap />} /> <Route path="app/projects/:id/roadmap.pdf" /> </Routes>