本文概述
- 参数说明
句法:
router.navigate(fragment, [options])
参数说明片段:它指定将在其中显示URL的参数的名称。
options:指定触发和替换之类的选项,以调用路由功能并更新URL。
【backbone.js路由导航navigate】让我们举个例子。
请参阅以下示例:
<
!DOCTYPE html>
<
head>
<
title>Router Navigate Example<
/title>
<
script src="http://img.readke.com/220416/06113K939-0.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/06113K049-1.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/06113M541-2.jpg" type="text/javascript"><
/script>
<
/head>
<
script type="text/javascript">
var RouteMenu = Backbone.View.extend({
el: '#routemenu', events: {
'click a' : 'onClick'
}, onClick: function( e ) {
router.navigate('/');
}
});
var Router = Backbone.Router.extend({
routes: {
'route/:id' : 'defaultRoute'
}, });
var routemenu = new RouteMenu();
Backbone.history.start();
<
/script>
<
body>
It refers to the view class 'RouteMenu' and creates the 3 links which changes the url when you click on the links
<
section id="routemenu">
<
ul>
<
li> <
a href="http://www.srcmini.com/#/route/1">route 1 <
/a> <
/li>
<
li> <
a href="http://www.srcmini.com/#/route/2">route 2 <
/a> <
/li>
<
li> <
a href="http://www.srcmini.com/#/route/3">route 3 <
/a> <
/li>
<
/ul>
<
/section>
<
/body>
<
/html>
输出:
将以上代码保存在navigation.html文件中,然后在新的浏览器中打开该文件。
文章图片
推荐阅读
- backbone.js路由执行execute
- backbone.js路由route
- backbone.js路由初始化
- backbone.js路由routes
- backbone.js路由器扩展extend
- backbone.js路由教程
- backbone.js集合create
- backbone.js集合fetch
- backbone.js集合clone