can-href

  • page
can.view.href  

Deprecated 2.3

Use the routeUrl helper instead like: href="{{routeUrl prop=value}}".

Sets an element's href attribute so that its url will set the specified attribute values on can.route.

bindings.href(attrName, attrValue)

Sets an element's href attribute so that its url will set the specified attribute values on can.route.

Parameters

  1. attrName {String}

  2. attrValue {key}

Use

With no pretty routing rules, the following:

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

produces:

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

If pretty route is defined like:

can.route(":page/:id")

The previous use of can-href will instead produce:

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

You can use values from stache's scope like:

<li><a can-href='{page="recipe" id=recipeId}'>{{recipe.name}}</a></li>

If recipeId was 6:

<li><a href='#!page/6'>{{recipe.name}}</a></li>

If recipeId is observable and changes to 7:

<li><a href='#!page/7'>{{recipe.name}}</a></li>