Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegexpRoute and ExpressRoute Improving Params Output. #107

Closed
gauntface opened this issue Jan 6, 2017 · 1 comment
Closed

RegexpRoute and ExpressRoute Improving Params Output. #107

gauntface opened this issue Jan 6, 2017 · 1 comment
Assignees

Comments

@gauntface
Copy link

Library Affected: sw-routing

Browser & Platform: All

Issue or Feature Request Description:
At the moment the express and regex routes will pass in an object into the handle method with a 'params' value.

With a regex route of const regexRoute = /\/1234567890\/(\w+)\//; I'd expect to be able to access the capturing group via params, which we can do, but it's not labelled clearly.

The above would result in:

(args) => {
  args.params[0] -----> "/1234567890/test/"
  args.params[1] -----> "test"
  args.params.index -----> 21
  args.params.input -----> "http://localhost:3000/1234567890/test/"
}

Given that the args variable also includes args.url, the params.input value is not useful and params[0] is not exactly useful either.

With express, this follows the same pattern.

For express route of /:date/:id/test/I would expect params to have a data and id value, but it's just index values with '0' being route and 1 being the date value and 2 being the id value.

(args) => {
  args.params[0] -----> "/1234567890/some-id/test/"
  args.params[1] -----> 1234567890
  args.params[2] -----> "some-id"
  args.params.index -----> XX
  args.params.input -----> "/1234567890/some-id/test/"
}

I'd expect:

(args) => {
  args.params['date'] -----> "1234567890"
  args.params['id'] -----> "some-id"
}

Also worth nothing that the 'date' value in this example is parsed as a number rather than a string. Not sure if we should be consistent with that or not.

@gauntface gauntface changed the title RegexpRoute and ExpressRoute RegexpRoute and ExpressRoute Improving Params Output. Jan 6, 2017
@gauntface
Copy link
Author

Also with a route that has no params to capture, args.params is set to true. Should probably be undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants