Backbone.js路由方法用于定义路由器上应用程序对象的URL表示。它还包含来自URL的传入路由值。
句法:
router.routes
让我们举个例子。
请参阅以下示例:
<
!DOCTYPE html>
<
head>
<
title>Router Routes Example<
/title>
<
script src="http://img.readke.com/220416/0611015Y9-0.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/0611014926-1.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/0611015307-2.jpg" type="text/javascript"><
/script>
<
/head>
<
body>
<
script type="text/javascript">
var Router = Backbone.Router.extend({routes: {
'': 'myroute_1', 'myroute_2': 'myroute_2'
}, myroute_1: function(){
document.write("myroute_1 has been called.");
}, myroute_2: function(){
document.write("myroute_2 has been called.");
}, });
var appRouter=new Router;
Backbone.history.start();
<
/script>
<
/body>
<
/html>
输出:
【backbone.js路由routes】将以上代码保存在routes.html文件中,然后在新的浏览器中打开该文件。
文章图片
推荐阅读
- backbone.js路由初始化
- backbone.js路由器扩展extend
- backbone.js路由教程
- backbone.js集合create
- backbone.js集合fetch
- backbone.js集合clone
- backbone.js集合parse
- backbone.js集合url
- backbone.js集合findwhere