chaplinjs/chaplin — pull request #682 by YAndrew91 (2013-09-11 13:39:38+00:00)
Title: Improved Routing API and query parameters support. Optimizations & refactoring.

Should close #664, #677, #577 (as a temp solution),

Change log:

* Supports the following signatures of the `redirectTo`:

```CoffeeScript
@redirectTo 'routeName', {id: 999}, options
@redirectTo 'controllerName#actionName', {id: 999}, options
@redirectTo {name: 'routeName'}, {id: 999}, options
@redirectTo {controller: 'controllerName', action: 'actionName'}, {id: 999}, options
@redirectTo {url: 'URL'}, options
```

Where `options` are optional. Sectional params hash (`{id: 999}`) may be optional too if an appropriate route doesn't require any.

Also, sectional params hash can be replaced everywhere by an array: `[999]`.

* Now you can pass `options.query` (hash or string) into a `redirectTo` only when redirecting by a route name or a controller&action pair. You aren't allowed to do it when using a direct URL, instead you should include a query string into the URL in this case.

* `Route::reverse` (as well as `Router::reverse`) are now able to add query parameters to the reversed URL, no matter if they are already stringified or not when passed into the reverse (as a third parameter).

* Parsing and stringifying of query parameters is now done by two appropriate methods of `chaplin/lib/utils`: both of them are inside an object `utils.QueryParams` and can be easily overridden if a base implementation isn't enough for your project.

* `Route::matches` improved not to return `true` when the only `controller` or `action` parameter passed.

* Refactoring&Optimization. For the moment `Router::route` method does a double work when passing a route name: first it makes a `Router::reverse` to get an URL, and then it tries to find a route we need again. I've changed this approach to a more clear one, without tasks repetition.

TODO: I'm now working on the additional change, descussed below the following post:
https://github.com/chaplinjs/chaplin/pull/634#issuecomment-24020944
I'll add a branch from the current `YAndrew91:routing` and then will merge if you approve.

NOTE: still requires a patch for Backbone, need to decide how to better integrate this:
https://github.com/dbk2/backbone/commit/6f51dc2fe1e84d176caf13fa7cbb80d72ab829ff
I also can add a branch with my implementation, I'm working on this.

For more details see a full discussion:
https://github.com/chaplinjs/chaplin/pull/634#issuecomment-23615953