2016-08-08 40 views
1

的前面刪除哈希我創建了一個簡單的應用程序與骨幹和木偶。它的工作正常,沒有錯誤或類似的東西。但是,當我看到URL,它在網址前面的哈希,這裏是我的鏈接主幹:從網址

programming/index.html#chart 
programming/index.html#tutorial/3 
programming/index.html#tutorial/6 

我想使它更清潔,更可讀,我想刪除hastag和/所以URL看起來像更換這

programming/index.html/chart 
programming/index.html/tutorial/3 
programming/index.html/tutorial/6 

,並且可以訪問這也

programming/chart 
programming/tutorial/3 
programming/tutorial/6 

我想太多這個問題的答案

Routing in Backbone.js/Marionette.js - no hashtags, route list and sub-routers

BackboneJS - Router issues - how to get clean URL's

我試圖讓pushState的爲真,這樣

programming.on('start',function(){ 
    if(Backbone.history){ 
     Backbone.history.start({ 
      pushState : true 
     }); 

     if(this.getCurentRoute() === ""){ 
      programming.trigger("program:list") 
     } 
    } 
}) 

我試圖讓.htaccess文件

<IfModule mod_rewrite.c> 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)$ /#$1 [R,L,NE] 
</IfModule> 

但他們都不適合我:(請大家幫我。

+1

我不認爲你可以做到這一點,因爲如果你刪除散列,那麼它會去服務器端路由而不是客戶端路由,你需要散列非HTML5瀏覽器 –

回答

0

這對我有用。

$('body').delegate('a[href]:not([href^=\#])', 'click', function (e) { 
    e.preventDefault(); 
    Backbone.history.navigate($(this).attr('href'), {trigger: true}); 
});