Kendo UI 单页面应用(二) Router 类
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 类的更多相关文章
- Kendo UI开发教程(24): 单页面应用(二) Router 类
Route类负责跟踪应用的当前状态和支持在应用的不同状态之间切换.Route通过Url的片段功能(#url)和流量器的浏览历史功能融合在一起.从而可以支持把应用的某个状态作为书签添加到浏览器中.Rou ...
- Kendo UI 单页面应用(四) Layout
Kendo UI 单页面应用(四) Layout Layout 继承自 View,可以用来包含其它的 View 或是 Layout.下面例子使用 Layout 来显示一个 View <div i ...
- Kendo UI 单页面应用(三) View
Kendo UI 单页面应用(三) View view 为屏幕上某个可视部分,可以处理用户事件. View 可以通过 HTML 创建或是通过 script 元素.缺省情况下 View 将其所包含的内容 ...
- Oracle JET 单页面应用程序Router 使用(上)
单页面应用程序:使用一个进加载一次的网页,如果页面由于用户的交互而改变,则仅绘制更改的页面部分. 要创建单页面应用程序需要使用 oj.Router 的虚拟导航来支持,ojModule 用来响应页面的重 ...
- Asp.net mvc Kendo UI Grid的使用(二)
上一篇文章对Kendo UI做了一些简单的介绍以及基本环境,这篇文章来介绍一下Grid的使用 先上效果图: 要实现这个效果在Controller在要先导入Kendo.Mvc.UI,Kendo.Mvc. ...
- [置顶] Kendo UI开发教程: Kendo UI 示例及总结
前面基本介绍完Kendo UI开发的基本概念和开发步骤,Kendo UI的示例网站为http://demos.kendoui.com/ ,包含了三个部分 Web DemoMobile DemoData ...
- HTML5 UI框架Kendo UI Web自定义组件(一)
Kendo UI Web包含数百个创建HTML5 web app的必备元素,包括UI组件.数据源.验证.一个MVVM框架.主题.模板等.在Kendo UI Web中如何创建自定义组件呢,在下面的文章中 ...
- [转]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 . ...
- vue 单页面(SPA) history模式调用微信jssdk 跳转后偶尔 "invalid signature"错误解决方案
项目背景 vue-cli生成的单页面项目,router使用history模式.产品会在公众号内使用,需要添加微信JSSDK,做分享相关配置. 遇到的问题 相关配置与JS接口安全域名都已经ok,发布后, ...
随机推荐
- HDU3974(dfs+线段树)
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- selectedIndex 属性可设置或返回下拉列表中被选选项的索引号。
转自:https://blog.csdn.net/xxj19950917/article/details/73002046
- html中NAME和ID区别
html中NAME和ID区别 NAME 的最大作用就是可以与服务端进行交互.Struts2中要设NAME的属性才能在Action中取到值,ID取不到. id与name的作用,作为标签的标识符,基本上是 ...
- Codeforces Round #401 (Div. 2)【A,B,C,D】
最近状态极差..水题不想写,难题咬不动..哎,CF的题那么简单,还搞崩了= =.真是巨菜无比. Codeforces777A 题意:略. 思路: 构造出3!次变换,然后输出就好. Code: #inc ...
- Keras输出每一层网络大小
示例代码: model = Model(inputs=self.inpt, outputs=self.net) model.compile(loss='categorical_crossentropy ...
- uoj#280. 【UTR #2】题目难度提升(构造)
传送门 咱先膜一下\(GXZ\)再说 我们先把序列从小到大排序,然后分情况讨论 无解是不存在的,从小到大输出所有数肯定可行 情况一,如果\(a[mid]=a[mid+1]\),因为最终的中位数也是它们 ...
- append、replace、replaceAll、indexof、lastIndexOf、substring的用法
1.append StringBuffer buf = new StringBuffer("Hard "): String aString = "Waxworks& ...
- 洛谷P3831 回家的路
题目背景 SHOI2012 D2T1 题目描述 \(2046\) 年 \(OI\) 城的城市轨道交通建设终于全部竣工,由于前期规划周密,建成后的轨道交通网络由\(2n\)条地铁线路构成,组成了一个\( ...
- Domination
题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read(){ , f ...
- String常用方法简介
1. 创建String对象的常用方法 (1) String s1 = "mpptest" (2) String s2 = new String(); (3) String s3 ...