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 can-route-pushstate or can-route-mock. It defaults to can-route-hash.
The following shows setting urlData
to another observable.
import {route, RouteMock} from "can/everything";
// route.data will update routeMock and be updated by changes in
// routeMock.
const routeMock = route.urlData = new RouteMock();
const routeData = route.data;
// begin binding
route.start()
// simulate setting the URL
routeMock.value = "foo=bar";
console.log( 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"#!"