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

Handle URL parameters #38

Open
polux opened this issue Jun 24, 2013 · 6 comments
Open

Handle URL parameters #38

polux opened this issue Jun 24, 2013 · 6 comments
Assignees

Comments

@polux
Copy link

polux commented Jun 24, 2013

Would it make sense to support URL parameters?

I've been using route with an app that used to do routing manually, sometimes using URL parameters. I want to maintain compatibility with the already published URLs for this app so I have to hack around routes to get it done (by capturing the URL parameters).

It would be nice to have native support for it.

@sethladd
Copy link
Contributor

sethladd commented Jul 1, 2013

/sub

@ghost ghost assigned justinfagnani Jul 5, 2013
@justinfagnani
Copy link
Owner

The hierarchical branch has some query parameter support. We're working on a new version of that branch and will bring it into master soon.

Some notes on how this might work:

Right now my thinking is that Routers will allow for more than one simultaneous match, so that you could have independently controlled parts of the UI. Routes will then match against pretty arbitrary application state, including the current URI path, fragment, query parameters, and possibly other any other state.

For something like query parameters, there may be cases where you want to match against a key/value pair regardless of other state like the path, and there may be cases where you only want to match a key/value pair when already in some other state. The way this dependency will be expressed is via the query matching route's location in the route hierarchy. If it's at the top level, it's independent of what state the rest of the Router is in. If it's mounted under some path Routes, then it only matches if it's ancestors match as well.

@polux
Copy link
Author

polux commented Jul 5, 2013

Sounds perfect!

@polux
Copy link
Author

polux commented Nov 4, 2013

The hierarchical branch has some query parameter support.

Could you please point me to the line in the hierarchical branch that handles them? (Or even better an example.) I see how URLs like /foo/:x/bar are supported (via parameters in RouteEvent) but I couldn't find a way of getting my hands on x: v in /foo?x=v.

@pavelgj
Copy link
Contributor

pavelgj commented Nov 4, 2013

Currently, in hierarchical branch, query parameters are namespaced -- they must be prefixed with the route name. For example. for URL: /foo/bar?bar.baz=1234

router.root
  ..addRoute(name: 'foo', path: '/foo', mount: (r) => r
    ..addRoute(name: 'bar', path: '/bar'))
expect(router.root.getRoute('foo.bar').parameters['baz'], '1234');

This API is a... work in progress...

@polux
Copy link
Author

polux commented Nov 4, 2013

Thanks for the explanation, good to know! I guess I'll stick with the current solution until there's support for arbitrary parameter names.

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

4 participants