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
      • static
        • current
        • data
        • deparam
        • link
        • matched
        • param
        • ready
        • url
    • can-route-pushstate
    • can-set
    • can-stache
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-route
  • /
  • link
  • / On this page
    • link

      function

      Creates a string representation of an anchor link using data and the registered routes.

      • source

      route.link(innerText, data, props [, merge])

      Make an anchor tag (<A>) that when clicked on will update can-route's properties to match those in data.

      Parameters

      1. innerText {Object}:

        The text inside the link.

      2. data {Object}:

        The data to populate the route with.

      3. props {Object}:

        Properties for the anchor other than href.

      4. merge {Boolean}:

        Whether the given options should be merged into the current state of the route.

      Returns

      {String}:

      A string with an anchor tag that points to the populated route.

      Creates and returns an anchor tag with an href of the route attributes passed into it, as well as any properties desired for the tag.

      route.link( "My videos", { type: "videos" }, {}, false )
        // -> <a href="#!type=videos">My videos</a>
      

      Other attributes besides href can be added to the anchor tag by passing in a data object with the attributes desired.

      route.link( "My videos", { type: "videos" },
        { className: "new" }, false )
          // -> <a href="#!type=videos" class="new">My Videos</a>
      

      It is possible to utilize the current route options when making anchor tags in order to make your code more reusable. If merge is set to true, the route options passed into canRoute.link will be passed into the current ones.

      location.hash = "#!type=videos"
      route.link( "The zoo", { id: 5 }, true )
        // -> <a href="#!type=videos&id=5">The zoo</true>
      
      location.hash = "#!type=pictures"
      route.link( "The zoo", { id: 5 }, true )
        // -> <a href="#!type=pictures&id=5">The zoo</true>
      

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