can-stache-route-helpers
Adds routeUrl and routeCurrent helpers to stache.
undefined
The can-stache-route-helpers module doesn't export anything. It mixes in the following can-stache helpers that use can-route:
routeUrl(hashes) The example below shows how to produce a hyperlink reference on an anchor element using the
routeUrl
helper.<mock-url></mock-url> <cooking-example></cooking-example> <script type="module"> import {Component} from "can"; import "//unpkg.com/mock-url@5"; Component.extend({ tag: "cooking-example", view: `<a href='{{ routeUrl(page="recipe" id=5) }}'>{{recipe.name}}</a>`, ViewModel: { recipe: { default() { return {name: "apple pie"}; } } } }); </script>
routeCurrent(hash) The next example shows how to use
routeCurrent
helper. If the url matches the parameters inrouteCurrent
it will add the'active'
class to the list item, changing the background color:<mock-url></mock-url> <cooking-example></cooking-example> <style> .active { color: black; text-decoration: none; } </style> <script type="module"> import {Component} from "can"; import "//unpkg.com/mock-url@5"; Component.extend({ tag: "cooking-example", view: `<li> <a {{# routeCurrent(page="recipe" id=5) }}class='active'{{/ routeCurrent }} href='{{ routeUrl(page="recipe" id=5) }}'>{{recipe.name}}</a> </li>`, ViewModel: { recipe: { default() { return {name: "apple pie"}; } } } }); </script>