iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 413 forks source link

Parameters can't have *s in them #1590

Open edemaine opened 7 years ago

edemaine commented 7 years ago

I have a regular route (no wildcards), and a form submission that triggers a Router.go, like so:

Router.route '/:group/search/:search',
  name: 'search'
  subscriptions: -> [
    Subscribe.subscribe 'messages.search', @params.group, @params.search
    Subscribe.subscribe 'groups.members', @params.group
    Subscribe.subscribe 'files', @params.group
  ]
  data: ->
    group: @params.group
    search: @params.search

Template.layout.events
  'submit .searchForm': (e, t) ->
    e.preventDefault()
    e.stopPropagation()
    Router.go 'search',
      group: routeGroup()
      search: t.find('.searchText').value

However, if the user enters text with one or more asterisks (*), this throws an error You are trying to access a wild card parameter at index 0 but the value of params at that index is undefined. The same happens with pathFor and urlFor, as reported in #708. The workaround I've found is the following:

    Router.go 'search',
      group: routeGroup()
      search: t.find('.searchText').value
      0: '*'
      1: '*'
      2: '*'
      3: '*'
      4: '*'
      5: '*'
      6: '*'
      7: '*'
      8: '*'
      9: '*'

But this still limits the number of asterisks the user can enter to 10. Fine for now, but feels like a bug (and it's been annoying to work around it every time I use pathFor and urlFor). It seems that *s should only be interpreted in the route specification, not in the arguments... or maybe I don't understand what wildcards are for.