fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Add support to pass pathToRegexp options #203

Closed danielr18 closed 1 year ago

danielr18 commented 6 years ago

Routes can be further customised if we can change the default pathToRegexp options, I'm proposing 2 ways to do that.

1 - Global pathToRegexp options passing them to the Routes constructor.

const pathToRegexpOpts = {sensitive: true}
const routes = nextRoutes({pathToRegexpOpts})
  .add('/Category/:id', 'category')
  .add('/category/:id', 'other_category')

This would solve https://github.com/fridays/next-routes/issues/147.

2 - Per route pathToRegexp options passing them to the add function.

const routes = nextRoutes().add('c', '/c', 'c', {pathToRegexp: {strict: true}})

Per route options would be merged with global options.

This implementation shouldn't break the current usage. I'm planning to update the documentation to explain the usage in another commit if you like the PR.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.05%) to 94.882% when pulling d3a707b104d9f0b1b8980216426e459af678c275 on danielr18:add-support-pathtoregexp-options into 08e8bbeaa76c5ec194abea388a193bedac7f35fc on fridays:master.

huv1k commented 6 years ago

@fridays any news on it? :)