Riot's routing system is based on hashChange [point change ]. There are two ways to monitor anchor changes: Riot's routing system is based on hashChange [anchor changes ]. There are two ways to listen for changes to the anchor:
Riot. route and riot.route.exe c
The differences between the two are as follows:
1. exec is executed only once after the page is loaded.
2. After the route page is loaded, it will not be automatically executed
3. The route command is executed only when the anchor point changes.
The two are used in the same way, but the execution time is different. Here is an example of exec.
The default values are as follows:
[Code] //... /index.html #123/dazongxiong riot.route.exe c (function (id, name) {// id = 123, name = da zongxiong console. log (id, name );});
The callback parameter of the route. It is separated by "/" by default.
Riot also provides the method to rewrite the default route value:
[Code] // define a new route value :#! /User/home? Id = 123 & name = xxxriot. route. parser (function (path) {// path is hash [the part where # is removed] =>! /User/home? Id = 123 & name = xxx var raw = path. slice (1). split ("? "); Var uri = raw [0], qs = raw [1], params = {}; // if (qs) {qs. replace (/([^ = &] *) = ([^ &]) */g, function (str, key, value) {params [key] = value; return str ;}) ;}; // enter riot.route.exe c () and riot. return [uri, params];}) of the 1st and 2nd parameters of route ();
The new routing listener can be used as follows:
[Code] // if the link is as follows :#! /User/home? Id=123&name=xxxriot.route.exe c (function (uri, qs) {// uri =/user/home // qs = {id: 123, name: "xxx "}});
Although the history api is not used to modify the link, the anchor is sufficient.
The above is the content of riot. js learning [9] routing. For more information, please follow the PHP Chinese Network (www.php1.cn )!