Next-routes: Apply delimiter to route param

Created on 17 Jun 2017  路  2Comments  路  Source: fridays/next-routes

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 ','?

Most helpful comment

@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

All 2 comments

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)

@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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

exogenesys picture exogenesys  路  3Comments

breeny picture breeny  路  5Comments

haotangio picture haotangio  路  5Comments

adekbadek picture adekbadek  路  4Comments

jchiellini picture jchiellini  路  4Comments