{{routeUrl hashes}}

  • function
can.stache.helpers.routeUrl  

Returns a url using can.route.url.

{{routeUrl hashes [,merge]}}

Passes the hashes to can.route.url and returns the result.

Parameters

  1. hashes {Expressions}

    A hash expression like page='edit' recipeId=id.

  2. merge {Boolean}Optional

    Pass true to create a url that merges hashes into the current can.route properties. Passing the merge argument is only available in Call expressions like routeUrl(id=itemId, true).

Returns

{String}

Returns the result of calling can.route.url.

Use

Use the routeUrl helper like:

<a href='{{routeUrl page="recipe" id=5}}'>{{recipe.name}}</a>

This produces (with no pretty routing rules):

<a href='#!&page=5&id=5'>{{recipe.name}}</a>

It this functionality could also be written as:

<a href='{{ routeUrl(page="recipe" id=5) }}'>{{recipe.name}}</a>

Using call expressions/parenthesis lets you pass the merge option to can.route. This lets you write a url that only changes specified properties:

<a href='{{ routeUrl(id=5, true) }}'>{{recipe.name}}</a>

The following demo uses routeUrl and {{#routeCurrent hash}} to create links that update can.route's page attribute:

It also writes out the current url like:

{{ routeUrl(undefined,true) }}

This calls can.route.url({}, true) which has the effect of writing out the current url.