如何使用sammy设置基本url?
我四处寻找javascript路由库,来到Sammy,所以我正在学习它 到目前为止,我看到的所有示例都显示了基于域作为基本url进行路由的热点,如www.mydomain.com/#,然后所有路由都会继续 但是我在本地主机目录中的嵌套目录中做了一些尝试,比如/wwwroot/play/sammy/所以我的基本url是如何使用sammy设置基本url?,url,sammy.js,Url,Sammy.js,我四处寻找javascript路由库,来到Sammy,所以我正在学习它 到目前为止,我看到的所有示例都显示了基于域作为基本url进行路由的热点,如www.mydomain.com/#,然后所有路由都会继续 但是我在本地主机目录中的嵌套目录中做了一些尝试,比如/wwwroot/play/sammy/所以我的基本url是 http://localhost/~rockdeveloper/play/sammy/# 然后所有路线都必须继续,比如: http://localhost/~rockdevel
http://localhost/~rockdeveloper/play/sammy/#
然后所有路线都必须继续,比如:
http://localhost/~rockdeveloper/play/sammy/#/products
http://localhost/~rockdeveloper/play/sammy/#/clients
http://localhost/~rockdeveloper/play/sammy/#/search
有没有办法设置这个基本url,这样我就可以继续像这样配置sammy路由
get('#/products')
get('#/clients')
get('#/search')
到现在为止,我必须将主字符串连接到路由,我希望它比这更智能
baseurl='/~rockdeveloper/play/sammy/#/search';
get(baseurl + '#/products');
谢谢。Sammy是一个前端框架,您不需要提供baseurl,因为所有调用都是在客户端url的基础上进行的,pound符号后的其他路径仅供Sammy使用 例: 你的基本路径是
http://localhost/~rockdeveloper/play/sammy/
在所有这些方面。其余的只是sammy路线(将其视为GET params)
此外,您的路线必须以一种可以从锚点无缝调用的方式定义。以下是我的路由文件的一部分:
从您的观点来看,您可以简单地使用以下内容:
<a href="#/someroute/{{name}}"><i class="icon-bookmark"></i> {{name}}</a>
//le me here using mustache :{
//让我在这里用胡子:{
app = $.sammy('body', function() {
//define events
this.bind('addNew',function(e,data){
//data.name = data.name.split(' ').join('_');
for(x in mapa[data.element]){
if(mapa[data.element][x].name.toLowerCase() == data.name.toLowerCase()){
return alert('There is already an element with the same name');
break;
}
}
ap('Adding: '+data.element+' with the name: '+data.name);
mapa[data.element].push({name:data.name});
this.trigger('sections',{action:data.element});
});
// define routes
this.get('#/', function() {
$('#menuright').html('');
$('.customMenu').remove();
$('#holder').html('').attr({style:''});
});
this.get('#/someroute/:variable', function() {
/*
...
...
...
*/
});
this.before(function(){
if(typeof(app.historial)=='undefined'){
app.historial = [];
}
app.historial.unshift(this.path.split('#')[1]);
if(app.historial.length>2) app.historial.length = 2;
do_something();
});
});
<a href="#/someroute/{{name}}"><i class="icon-bookmark"></i> {{name}}</a>
//le me here using mustache :{