在Backbone.js中,我们使用路由器指定url格式并指定要重定向到的页面。
例如:
"serviceslist/:id/:serviceId": "serviceslist",
serviceslist: function(id, serviceId) {
var self = this;
this.load();
require([
'js/views/patient/serviceslist'
], function(serviceslist) {
self.shell();
if (typeof app.serviceslist !== 'undefined') {
app.serviceslist.destroy();
}
app.serviceslist = new serviceslist({ Id: id, fromouter: false, serviceId: serviceid });
$("#main-nav li.active").removeClass("active");
$("#admin").addClass("active");
});
},
我们在js中调用:
Backbone.history.navigate('#/serviceslist/1456/false/1111', { trigger: true });
链接将是:
http://localhost:64865/#/serviceslist/1456/false/1111
有没有办法加密网址的这一部分:1456/false/1111
?
答案 0 :(得分:0)
在需要转义的路线部件上使用encodeURIComponent
。
示例:
console.log(encodeURIComponent('Time &time=again'));
console.log('#/serviceslist/' + encodeURIComponent('1456&123/456') + '/false/1111')

所以你的导航代码可能是:
var id = '1456/false';
var serviceId = '1111';
Backbone.history.navigate('#/serviceslist/' + encodeURIComponent(id) + '/' + encodeURIComponent(serviceId), { trigger: true });
您可能需要在路由器上对其进行解码:
serviceslist: function (id,serviceId) {
// decode the route params :id & :serviceId
id = decodeURIComponent(id);
serviceId = decodeURIComponent(serviceId);
// the rest of your logic here
}