本文概述
- 参数说明
【backbone.js路由初始化】句法:
new Router(options)
参数说明options:它指定传递给初始化函数的值。
让我们举个例子。
请参阅以下示例:
<
!DOCTYPE html>
<
head>
<
title>Router Example<
/title>
<
script src="http://img.readke.com/220416/0611131014-0.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/061113Ka-1.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/061113F92-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 one has been called.");
}, myroute_2: function(){
document.write("myroute two has been called.");
}, });
var appRouter=new Router;
//It is an instantiation of the router using the 'new' keyword
Backbone.history.start();
<
/script>
<
/body>
<
/html>
输出:
将上面的代码保存在initialize.html文件中,然后在新的浏览器中打开该文件。
文章图片
推荐阅读
- backbone.js路由route
- backbone.js路由routes
- backbone.js路由器扩展extend
- backbone.js路由教程
- backbone.js集合create
- backbone.js集合fetch
- backbone.js集合clone
- backbone.js集合parse
- backbone.js集合url