URLを管理するには、jQuery.address(http://www.asual.com/jquery/address/)を使用することを検討してください。
jQuery.addressを使用すると、「http://example.com/#!/user/5」などのクロール可能なURLを設定し、アドレスの変更をリスンしてそれに応じて処理することができます。
自分のコードでは、次のようにsteal設定ファイル内からアドレスベースルータを設定します。
steal.plugins(
'jquery/controller',
'jquery/controller/subscribe',
'jquery/view/ejs',
'jquery/controller/view',
'jquery/model',
'jquery/dom/fixture',
'jquery/dom/form_params',
'steal/less')
.css('css/vendor/reset-fonts-grids')
.resources('vendor/jquery.address-1.3.1.min.js')
.models('user')
.controllers('user')
.views()
.then(function() {
steal.less('css/style');
// Set up a router
$.address.baseURL('/basePath');
// $.address.crawlable(true);
$.address.change(function(event) {
var path = event.path;
switch(true) {
// Matches http://example.com/#!/ or http://example.com/
case /^\/$/.test(path):
$('#page').empty();
break;
// Matches http://example.com/#!/user/42/profile
case /^\/user\/[0-9]+\/profile/.test(path):
var userId = path.split("/")[2];
// Instantiate and load a controller
new User.Controllers.User($('body'),userId);
break;
case /^\/search/.test(path):
$.log('search');
break;
default:
$.log(event.path);
}
});
});
は、あなたはそれがjQueryのと同じだ、あなたはJavascriptMVCルータを使用することができます
$.address.value('/user/10/profile');
出典
2011-01-08 05:30:52
asm