• function

deparam can.route.deparam

 

Extract data from a route path.

can.route.deparam( url )

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.

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

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

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

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

can.route(":type/:id")

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