DoneJS StealJS jQuery++ FuncUnit DocumentJS
5.33.3
6.0.0 4.3.0 3.14.1 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-bind
      • can-compute
      • can-debug
      • can-define
      • can-define/list/list
      • can-define/map/map
      • can-define-backup
      • can-define-stream
      • can-define-stream-kefir
      • can-event-queue
      • can-kefir
      • can-list
      • can-map
      • can-map-compat
      • can-map-define
      • can-observable-array
      • can-observable-object
      • can-observation
      • can-observation-recorder
      • can-observe
      • can-simple-map
      • can-simple-observable
      • can-stream
      • can-stream-kefir
      • can-value
    • Views
      • can-attribute-observable
      • can-component
      • can-stache
      • can-stache-bindings
      • can-stache-converters
      • can-stache-element
      • can-stache-route-helpers
      • can-view-autorender
      • can-view-callbacks
      • can-view-import
      • can-view-live
      • can-view-model
      • can-view-nodelist
      • can-view-parser
      • can-view-scope
      • can-view-target
      • steal-stache
    • Data Modeling
      • can-connect
      • can-connect-feathers
      • can-connect-ndjson
      • can-connect-tag
      • can-fixture
      • can-fixture-socket
      • can-local-store
      • can-memory-store
      • can-ndjson-stream
      • can-query-logic
      • can-realtime-rest-model
      • can-rest-model
      • can-set-legacy
      • can-super-model
    • Routing
      • can-deparam
      • can-param
      • can-route
        • static
          • currentRule
          • data
          • deparam
          • isCurrent
          • param
          • register
          • rule
          • start
          • stop
          • url
          • urlData
        • deprecated
          • link
      • can-route-hash
      • can-route-mock
      • can-route-pushstate
    • JS Utilities
      • can-assign
      • can-define-lazy-value
      • can-diff
      • can-globals
      • can-join-uris
      • can-key
      • can-key-tree
      • can-make-map
      • can-parse-uri
      • can-queues
      • can-string
      • can-string-to-any
      • can-zone-storage
    • DOM Utilities
      • can-ajax
      • can-attribute-encoder
      • can-child-nodes
      • can-control
      • can-dom-data
      • can-dom-events
      • can-dom-mutate
      • can-event-dom-enter
      • can-event-dom-radiochange
      • can-fragment
    • Data Validation
      • can-define-validate-validatejs
      • can-type
      • can-validate
      • can-validate-interface
      • can-validate-legacy
      • can-validate-validatejs
    • Typed Data
      • can-cid
      • can-construct
      • can-construct-super
      • can-data-types
      • can-namespace
      • can-reflect
      • can-reflect-dependencies
      • 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

link

  • Edit on GitHub

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

Deprecated 4.4.1

route.link has been deprecated in favor of can-stache-route-helpers.routeCurrent.

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. Creates and returns an anchor tag with a href of the route attributes passed into it, as well as any properties desired for the tag.

import {route} from "can";

const link = route.link( "My videos", { type: "videos" }, {}, false );
console.log( link ); //-> '<a href="#!&type=videos">My videos</a>'

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.

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

    import {route} from "can";
    
    const link = route.link( 
      "My videos", 
      { type: "videos" },
      { className: "new" },
      false
    );
    console.log( link ); //-> '<a href="#!&type=videos" class="new">My videos</a>'
    
  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.

Use

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.

import {route} from "can";

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

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

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

On this page

Get help

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