- It's still pretty confusing if you ask me and I haven't tested it with routes with params, but as long as it's passed in effectively in the two places, it should be fine.
- See the previous revision for some extended notes on the method flow
- tl;dr
utils.redirectTo()
->Router.route()
->Route.handler()
Route.handler()
will only callRoute.reverse()
if it receives an object (needed for URL query params) which happens if you leave out theurl
property in the object (first argument) passed intoredirectTo()
.
- tl;dr
Last active
August 29, 2015 14:01
-
-
Save naganowl/6fef926020b44e0b0b03 to your computer and use it in GitHub Desktop.
Solution to Chaplin route params with redirectTo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define (require, exports) -> | |
exports = (match) -> | |
match 'search', 'search#index', name: 'search' | |
match 'search/:query', 'search#query', name: 'query' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define (require, exports) -> | |
Chaplin = require 'chaplin' | |
exports = class SearchView extends Chaplin.View | |
initialize: -> | |
super | |
@delegate 'submit', 'form', (e) -> | |
e.preventDefault() | |
# `name` can also be a `path` object as specified in | |
# http://docs.chaplinjs.org/chaplin.router.html#route | |
# so doing `name = {name: 'query', query: 'foo'}` should work. | |
name = 'search' | |
term = @$('#search').val() | |
mode = 'email' if @$('#filter').is ':checked' | |
if term | |
Chaplin.utils.redirectTo( | |
{params: name, name} | |
null | |
query: {mode, term} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment