urlData
Specifies an observable value that represents the URL. Useful for changing what URL route is cross-bound to.
ValueObservable
urlData
is an observable value that represents the part of the URL cross
bound to the data state object. It can be set to other observable urls like <a href="can-route-pushstate.html" title="Changes can-route to use pushstate
to change the window's pathname instead
of the hash.
import route from "can-route-pushstate";
route( "{page}", { page: "home" } ); route.start();
route.attr( "page", "user" );
location.pathname; // -> "/user"">can-route-pushstate or can-route-mock. It defaults to can-route-hash.
The following shows setting urlData
to another observable.
import {route, RouteMock, DefineMap} from "can";
// route.data will update routeMock and be updated by changes in
// routeMock.
var routeMock = route.urlData = new RouteMock();
var routeData = route.data = new DefineMap({},false);
// begin binding
route.start()
// simulate setting the URL
routeMock.value = "foo=bar";
routeData.foo //-> "bar";
Creating your own ValueObservable
WARNING: The following is non-normative and may change in a future release. Please let us know if you are trying to create your own observable and we will work with you to stabilize the API.
Besides implementing the standard ValueObservable
symbols:
The ValueObservable
should include the following properties:
paramsMatcher
- A regular expression used to test if the URL is formatted correctly for deparam.querySeparator
- A string that separates when arbitrary key-value pairs begin in the url (Example:"?"
).root
- A string value used to identify the part of the url where routing begins. For example, can-route-hash defaults to"#!"