Kendo UI 单页面应用(二) Router 类

Route 类负责跟踪应用的当前状态和支持在应用的不同状态之间切换。Route 通过 Url 的片段功能(#url)和流量器的浏览历史功能融合在一起。从而可以支持把应用的某个状态作为书签添加到浏览器中。Route 也支持通过代码在应用的不同状态之间切换。

Router 根路径回调函数

<script>
var router = new kendo.Router(); router.route("/", function() {
console.log("/ url was loaded");
}); $(function() {
router.start();
});
</script>

缺省情况下,如果 URL fragment 为空,将使用缺省的“/”的根路径,此时对于的回调函数被调用,不管初始 URL 是什么,这个初始化的回调函数总会调用。如果使用 IE,按 F12 可以打开 Developer Window,选择 Console 可以看到 console.log 的打印信息。

参数

Router 支持 bound parameters, optional segments, 和 route globbing,类似于绑定参数,可选参数,匹配符匹配参数等。例如:绑定参数

<script>
var router = new kendo.Router(); router.route("/items/:category/:id", function(category, id) {
console.log(category, "item with", id, " was requested");
}); $(function() {
router.start(); // ... router.navigate("/items/books/59");
});
</script>

当运行这个页面时,注意地址栏中的地址为:

<http://localhost:53223/Index.html#/items/books/59 –> #/items/books/59>

可选参数

如果 URL 的部分参数为可选的,此时 Route 的规则为使用”()”,将可选参数放在括号内。

<script>
var router = new kendo.Router(); router.route("/items(/:category)(/:id)", function(category, id) {
console.log(category, "item with", id, " was requested");
}); $(function() {
router.start(); // ...
router.navigate("/items/books/59"); // ...
router.navigate("/items"); // ...
router.navigate("/items/books");
});
</script>

使用×通配符匹配参数

<script>
var router = new kendo.Router(); router.route("/items/*suffix", function(suffix) {
console.log(suffix);
}); $(function() {
router.start(); // ...
router.navigate("/items/books/59"); // ...
router.navigate("/items/accessories"); // ...
router.navigate("/items/books");
});
</script>

页面切换

navigation 方法可以用来切换应用,对应的路径的回调方法被调用, navigation 方法修改 URL 的 fragment 部分(#后面部分)。比如:

<a href="#/foo">Foo</a>

<script>
var router = new kendo.Router(); router.route("/foo", function() {
console.log("welcome to foo");
}); $(function() {
router.start();
router.navigate("/foo");
});
</script>

这个例子,将在地址栏显示 http://xxx/index.html#/foo。如果对应的路径不存在,Router 类触发 routeMissing 事件,并把 URL 作为参数传入。

<script>
var router = new kendo.Router({ routeMissing: function(e) { console.log(e.url) } }); $(function() {
router.start();
router.navigate("/foo");
});
</script>

你可以通过 change 事件来截获这种页面之间的切换,然后调用 preventDefault 阻止页面切换。

<script>
var router = new kendo.Router({
change: function(e) {
console.log(url);
e.preventDefault();
}
}); $(function() {
router.start();
router.navigate("/foo");
});
</script>

Kendo UI 单页面应用(二) Router 类的更多相关文章

  1. Kendo UI开发教程(24): 单页面应用(二) Router 类

    Route类负责跟踪应用的当前状态和支持在应用的不同状态之间切换.Route通过Url的片段功能(#url)和流量器的浏览历史功能融合在一起.从而可以支持把应用的某个状态作为书签添加到浏览器中.Rou ...

  2. Kendo UI 单页面应用(四) Layout

    Kendo UI 单页面应用(四) Layout Layout 继承自 View,可以用来包含其它的 View 或是 Layout.下面例子使用 Layout 来显示一个 View <div i ...

  3. Kendo UI 单页面应用(三) View

    Kendo UI 单页面应用(三) View view 为屏幕上某个可视部分,可以处理用户事件. View 可以通过 HTML 创建或是通过 script 元素.缺省情况下 View 将其所包含的内容 ...

  4. Oracle JET 单页面应用程序Router 使用(上)

    单页面应用程序:使用一个进加载一次的网页,如果页面由于用户的交互而改变,则仅绘制更改的页面部分. 要创建单页面应用程序需要使用 oj.Router 的虚拟导航来支持,ojModule 用来响应页面的重 ...

  5. Asp.net mvc Kendo UI Grid的使用(二)

    上一篇文章对Kendo UI做了一些简单的介绍以及基本环境,这篇文章来介绍一下Grid的使用 先上效果图: 要实现这个效果在Controller在要先导入Kendo.Mvc.UI,Kendo.Mvc. ...

  6. [置顶] Kendo UI开发教程: Kendo UI 示例及总结

    前面基本介绍完Kendo UI开发的基本概念和开发步骤,Kendo UI的示例网站为http://demos.kendoui.com/ ,包含了三个部分 Web DemoMobile DemoData ...

  7. HTML5 UI框架Kendo UI Web自定义组件(一)

    Kendo UI Web包含数百个创建HTML5 web app的必备元素,包括UI组件.数据源.验证.一个MVVM框架.主题.模板等.在Kendo UI Web中如何创建自定义组件呢,在下面的文章中 ...

  8. [转]Upgrading to Async with Entity Framework, MVC, OData AsyncEntitySetController, Kendo UI, Glimpse & Generic Unit of Work Repository Framework v2.0

    本文转自:http://www.tuicool.com/articles/BBVr6z Thanks to everyone for allowing us to give back to the . ...

  9. vue 单页面(SPA) history模式调用微信jssdk 跳转后偶尔 "invalid signature"错误解决方案

    项目背景 vue-cli生成的单页面项目,router使用history模式.产品会在公众号内使用,需要添加微信JSSDK,做分享相关配置. 遇到的问题 相关配置与JS接口安全域名都已经ok,发布后, ...

随机推荐

  1. POJ1523(割点所确定的连用分量数目,tarjan算法原理理解)

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7406   Accepted: 3363 Description C ...

  2. Ubuntu Hadoop环境搭建(Hadoop2.6.5+jdk1.8.0_121)

    1.JDK的安装 2.配置hosts文件(这个也要拷贝给所有slave机,scp /etc/hosts root@slave1:/etc/hosts) gedit /etc/hosts 添加: 122 ...

  3. Algorithms & Data structures in C++& GO ( Lock Free Queue)

    https://github.com/xtaci/algorithms //已实现 ( Implemented ): Array shuffle https://github.com/xtaci/al ...

  4. JAVA + SELENIUM--环境搭建

    一.安装JDK    可在JAVA官网http://www.java.com/zh_CN/download/ 中下载最新的JDK,并按提示安装    环境变量配置:我的电脑右键-->属性--&g ...

  5. win10 安装nodejs,报错there is a problem in the windows installer package

    今天重装了win10系统,开始安装各种软件,装到node的时候我崩溃了,报错there is a problem in the windows installer package··· 度娘了各种安装 ...

  6. Centos7.2 安装配置 Tengine(nginx)

    一.下载tengine wget http://tengine.taobao.org/download/tengine-2.2.2.tar.gz 二.安装tenginx(nginx)的模块依赖库 yu ...

  7. ZOJ 3512 Financial Fraud (左偏树)

    题意:给定一个序列,求另一个不递减序列,使得Abs(bi - ai) 和最小. 析:首先是在每个相同的区间中,中位数是最优的,然后由于要合并,和维护中位数,所以我们选用左偏树来维护,当然也可以用划分树 ...

  8. 安装Matlab出现Error 1935错误解决方法

    1.开始 - 运行(输入regedit.exe)- 确定或者回车,打开注册表编辑器: 2.在打开的注册表编辑器中找到:HKEY_LOCAL_MACHINE ,并展开:HKEY_LOCAL_MACHIN ...

  9. WebView根据加载的内容来控制其高度

    一.先设置WebView的高度为0,然后在其加载结束后的代理方法中根据contentSize设置其高度 //初始话一个UIWebView: self.webView = [[[UIWebView al ...

  10. GridView 中RowDataBound 获取绑定后的各个字段的值

    protected void GridView_dept_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType ...