routerfy
Nuxt like router for Express
install
npm install routerfy
Usage
Routerfy automatically generates the routes based on your file tree inside the routes directory.
const express = const routerfy = const app = app app
Basic routes
This file tree:
routes/
--| user/
-----| index.js
-----| one.js
--| index.js
will automatically generate:
- /
- /user
- /user/one
Dynamic routes
To define a dynamic route with a parameter, you need to define a JavaScript file OR a directory prefixed by an underscore.
This file tree:
routes/
--| _slug/
-----| comments.js
-----| index.js
--| users/
-----| _id.js
--| index.js
will automatically generate:
- /
- /users/:id
- /:slug
- /:slug/comments
Note: For dynamic routes to work properly, you must use the
mergeParams: true
javascript option when calling theexpress.Router
function
const router = ; router; moduleexports = router;