DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
    • can-define
    • can-define/list/list
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
    • can-stache
    • can-stache/helpers/route
      • {{#routeCurrent hash}}
      • {{routeUrl hashes}}
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-stache/helpers/route
  • /
  • {{routeUrl hashes}}
  • / On this page
    • {{routeUrl hashes}}

      function

      Returns a url using route.url.

      • source

      routeUrl( hashes... [,merge] )

      Calls url with hashes as it's data argument and an optional merge.

      This can be used on its own to create <a> hrefs like:

      <a href="{{ routeUrl(page='todos' id=todo.id) }}">details</a>
      

      Or in conjunction with other helpers:

      {{makeLink "details" routeUrl(page='todos', true)}}
      

      {{routeUrl [merge] hashes... }}

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

      <a href="{{routeUrl page='todos' id=todo.id}}">details</a>
      

      Parameters

      1. merge {Boolean}:

        Pass true to create a url that merges hashes into the current can-route properties.

      2. hashes {Hash Expression}:

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

      Returns

      {String}:

      Returns the result of calling 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 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 route.url({}, true) which has the effect of writing out the current url.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.