DoneJS StealJS jQuery++ FuncUnit DocumentJS
3.14.1
5.0.0 4.3.0 2.3.35
  • About
  • Guides
  • API Docs
  • Community
  • Contributing
  • Bitovi
    • Bitovi.com
    • Blog
    • Design
    • Development
    • Training
    • Open Source
    • About
    • Contact Us
  • About
  • Guides
  • API Docs
    • Observables
      • can-compute
      • can-define
      • can-define/list/list
      • can-define/map/map
      • can-define-stream
      • can-define-stream-kefir
      • can-event
      • can-event/async/async
      • can-event/batch/batch
      • can-event/lifecycle/lifecycle
      • can-kefir
      • can-list
      • can-map
      • can-map-backup
      • can-map-define
      • can-observation
      • can-observe
      • can-simple-map
      • can-simple-observable
      • can-stream
      • can-stream-kefir
    • Data Modeling
      • can-connect
      • can-connect-cloneable
      • can-connect-feathers
      • can-connect-ndjson
      • can-connect-signalr
      • can-fixture
      • can-fixture-socket
      • can-ndjson-stream
      • can-set
    • Views
      • can-component
      • can-ejs
      • can-element
      • can-react-component
      • can-stache
      • can-stache/helpers/route
        • {{#routeCurrent(hash)}}
        • {{routeUrl(hashes)}}
      • can-stache-bindings
      • can-stache-converters
      • can-view-autorender
      • can-view-callbacks
      • can-view-href
      • can-view-import
      • can-view-live
      • can-view-model
      • can-view-nodelist
      • can-view-parser
      • can-view-scope
      • can-view-target
      • react-view-model
      • react-view-model/component
      • steal-stache
    • Routing
      • can-deparam
      • can-param
      • can-route
      • can-route-pushstate
    • JS Utilities
      • can-assign
      • can-define-lazy-value
      • can-globals
      • can-key-tree
      • can-make-map
      • can-parse-uri
      • can-string
      • can-string-to-any
      • can-util
      • can-zone
      • can-zone-storage
    • DOM Utilities
      • can-ajax
      • can-attribute-encoder
      • can-control
      • can-dom-events
      • can-event-dom-enter
      • can-event-dom-radiochange
      • can-jquery
    • Data Validation
      • can-define-validate-validatejs
      • can-validate
      • can-validate-interface
      • can-validate-legacy
      • can-validate-validatejs
    • Typed Data
      • can-cid
      • can-construct
      • can-construct-super
      • can-namespace
      • can-reflect
      • can-reflect-promise
      • can-types
    • Polyfills
      • can-symbol
      • can-vdom
    • Core
    • Infrastructure
      • can-global
      • can-test-helpers
    • Ecosystem
    • Legacy
  • Community
  • Contributing
  • GitHub
  • Twitter
  • Chat
  • Forum
  • News
Bitovi

{{#routeCurrent(hash)}}

  • Edit on GitHub

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

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=recipe&id=5, this produces:

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

This functionality could also be written as a call expression:

<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.14.1.

On this page

Get help

  • Chat with us
  • File an issue
  • Ask questions
  • Read latest news