fridays / next-routes

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

Apply delimiter to route param #50

Closed paulwehner closed 7 years ago

paulwehner commented 7 years ago

I have a url that looks like:

http://localhost:3000/r/proud,cozy

And then have a route that looks like:

const nextRoutes = require('next-routes') const routes = module.exports = nextRoutes() routes.add('recommendations', '/r/:e')

This returns a query like:

{e: "proud,cozy"}

However I would like this returned instead:

{e: ["proud","cozy"]}

How could I apply a delimiter to the route, so that it knows that there can be one or more ':e', and that it would be split by ','?

fridays commented 7 years ago

Maybe this helps: https://github.com/fridays/next-routes/pull/2

It let's you pass an array to generate a repeat path segment. I think you still have to do .split() when receiving the value (check path-to-regexp)

joncursi commented 6 years ago

@fridays is there a way to customize the delimiter character? By default it uses / (%2F) but I would like to use the pipe | instead. My use-case is on query parameters. Example:

Router.pushRoute('Home', {
  items: ['ONE', 'TWO', 'THREE'],
});
http://website.com?items=ONE|TWO|THREE   <-- I want this
http://website.com?items=ONE%2FTWO%2FTHREE   <-- I don't want this