0.0.341 • Published 6 years ago
routematic v0.0.341
- Creates named routes
- Check if a route matches a defined route
- Batch create routes
- Can use on server and client
const route = require('routematic');Create Routes
route.to('/home').as('homepage');
route.get('homepage')
// /homepageNamespace a group of routes
const authPaths = routematic({
namespace: 'auth'
})
authPaths.to('/users/login').as('users.login')
authPaths.get('users.login')
// auth/users/loginUse routes with url params
route.to('/posts/:id').as('post.show');
route.get('post.show', { id: 123 })
// posts/123Extract params from routes
route.to('/posts/:id').as('post.show');
route.url('/product/123').params()
// { id: "123" }Splats
route.to('/product/*name').as('product.show');
route.url('/product/123').is('product.show')
// trueGet the routes params
route.to('/product/*name').as('product.show');
route.url('/product/123').params()
// { name: 123 }Check if a route matches
route.to('/posts/:id').as('post.show');
route.to('/users/:id').as('users.show');
route.to('/product/*').as('product.show');
route.url('/posts/123').is('post.show')
// true
route.url('/posts/123').is('users.show')
// false
route.url('/product/tooth-paste').is('product.show')
// trueBatch define routes
route.define({
'/users/:id': 'users.show',
'/posts/:id': 'posts.show',
})Print all routes
route.all()
/*
{
'/users/:id': 'users.show',
'/posts/:id': 'posts.show',
}
*/