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
  • /
  • {{#routeCurrent hash}}
  • / On this page
    • {{#routeCurrent hash}}

      function

      Returns if the hash values match the can-route's current properties.

      • source

      routeCurrent( hashes... [,subsetMatch] )

      Calls route.current with hashes and returns the result. This can be used in conjunction with other helpers:

      {{linkTo "Todos" routeCurrent(page='todos' id=todo.id)}}
      

      Or on its own:

      <a class="{{#routeCurrent(page='todos',true) }}active{{/routeCurrent}}">Todos</a>
      

      Parameters

      1. hashes {Hash Expression}:

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

      2. subsetMatch {Boolean}:

        If an optional true is passed, routeCurrent will return true if every value in hashes matches the current route data, even if the route data has additional properties that are not matched.

      Returns

      {Boolean}:

      Returns the result of calling route.current.

      {{#routeCurrent [subsetMatch] hashes...}}FN{{else}}INVERSE{{/routeCurrent}}

      Renders FN if the hashes passed to route.current returns true. Renders the INVERSE if route.current returns false.

      <a class="{{#routeCurrent true page='todos'}}active{{/routeCurrent}}">Todos</a>
      

      Parameters

      1. subsetMatch {Boolean}:

        If an optional true is passed, routeCurrent will return true if every value in hashes matches the current route data, even if the route data has additional properties that are not matched.

      2. hashes {Hash Expression}:

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

      3. FN {sectionRenderer(context, helpers)}:

        A subsection that will be rendered if the current route matches hashes.

      4. INVERSE {sectionRenderer(context, helpers)}:

        An optional subsection that will be rendered if the current route does not match hashes.

      Returns

      {String}:

      The result of SUBEXPRESSION or {{else}} expression.

      Use

      Use the routeCurrent helper like:

      <li {{#routeCurrent page="recipe" id=5}}class='active'{{/routeCurrent}}>
        <a href='{{routeUrl page="recipe" id=5}}'>{{recipe.name}}</a>
      </li>
      

      With default routes and a url like #!&page=5&id=5, this produces:

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

      It this functionality could use call expressions like:

      <li {{#routeCurrent(page="recipe" id=5)}}class='active'{{/routeCurrent}}>
        <a href='{{ routeCurrent(page="recipe" id=5) }}'>{{recipe.name}}</a>
      </li>
      

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

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