0.0.341 • Published 4 years ago

routematic v0.0.341

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago
  • 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')

  // /homepage

Namespace a group of routes

const authPaths = routematic({
  namespace: 'auth'
})

authPaths.to('/users/login').as('users.login')

authPaths.get('users.login')

// auth/users/login

Use routes with url params

  route.to('/posts/:id').as('post.show');
  route.get('post.show', { id: 123 })

  // posts/123

Extract 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')
  // true

Get 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')
  // true

Batch 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',
}
*/
0.0.33

4 years ago

0.0.34

4 years ago

0.0.341

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.3

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago