Riot. js learn Routing

Source: Internet
Author: User
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.