A flexible router for Bloggify apps.
# Using npm
npm install --save bloggify-flexible-router
# Using yarn
yarn add bloggify-flexible-router
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. 🐛
If the routes (default: app/routes
) folder exists, it will dictate the routes structure. For example:
_
is alias for index
. _foo
is alias for :foo
routes/
├── 404.ajs << 404 page
├── _.ajs << The index page (loaded on `/`)
├── api << Rest API (`/api`)
│ ├── index.js << Api Handlers (e.g. sending a custom 404)
│ └── users << The `/api/users[/...]` endpoint
│ ├── index.js << Handling `/api/users` (sending the list of users)
│ └── _username << Handling `/api/users/:username`
│ └── index.js << Fetching the user, by username, and sending it
└── users << The users list, in HTML format (`/users`)
├── _.ajs << The `/users` view
├── _.js << The `/users` controler
└── _user << `/users/:user` endpoint
├── _.ajs << View
└── _.js << Controller
The controller files look like this:
// Before hook
exports.before = (ctx, cb) => ...
// After hook
exports.after = (ctx, cb) => ...
// Handle all the methods
// Alias for module.exports = ctx => ...
exports.all = ctx => ...
// Handle post requests
exports.post = ctx => ...
- Object
config
: routes_dir
(String): The path to the directory where the routes are stored. They should be randable view files. For dynamic routes, use the_
character.
"/path/to/route": { controllerPath, viewPath }
Have an idea? Found a bug? See how to contribute.
If you are using this library in one of your projects, add it in this list. ✨
bloggify
bloggify-cli