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
  • /
  • deparam
  • / On this page
    • deparam

      function

      Extract data from a route path.

      • source

      route.deparam(url)

      Extract data from a url, creating an object representing its values.

      route("{page}");
      
      var result = route.deparam("page=home");
      console.log(result.page); // -> "home"
      

      Parameters

      1. url {String}:

        A route fragment to extract data from.

      Returns

      {Object}:

      An object containing the extracted data.

      Creates a data object based on the query string passed into it. This is useful to create an object based on the location.hash.

      route.deparam("id=5&type=videos");
        // -> { id: 5, type: "videos" }
      

      It's important to make sure the hash or exclamation point is not passed to route.deparam otherwise it will be included in the first property's name.

      route.data.id = 5 // location.hash -> #!id=5
      route.data.type = "videos"
        // location.hash -> #!id=5&type=videos
      route.deparam(location.hash);
        // -> { #!id: 5, type: "videos" }
      

      route.deparam will try and find a matching route and, if it does, will deconstruct the URL and parse out the key/value parameters into the data object.

      route("{type}/{id}");
      
      route.deparam("videos/5");
        // -> { id: 5, route: "{type}/{id}", type: "videos" }
      

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