I'm using Backbone with Marionette.
I have a link <a> tag where I'm passing few parameters, how can I extract those values in other pages using Backbone?
<a href="http://localhost.com:8080/help/?name=matth&age=25&[email protected]">View Details</a>
Address Bar url:
http://localhost.com:8080/help/?name=matth&age=25&[email protected] 44
Using Php, this is straightforward:
$Url = $_GET['state']."#".$_GET['city'];
How can I achieve it within my Backbone app?
If the route is defined with something like this:
Then you can access those params in the
helpfunction just by defining them in the signature of the method (within the backbone router),In your case, this will give you params like this:
So the proper routing would be
Where parentheses make a part optional.
Backbone docs
Note that the order is important and the following url wouldn't trigger the route callback. Notice the
emailandageparams placement.In order to trigger a route regardless of the number of params and their ordering, take a look at how to parse the query string in the route function, but that won't always work.