主干:删除URL前面的散列

Backbone : Remove hash from front in URL

本文关键字:前面 URL 删除 主干      更新时间:2023-09-26

我用Backbone和Marionette创建了一个简单的应用程序。它工作正常,没有错误或类似的东西。但当我看到URL时,它在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

我尝试了这个问题的大部分答案

Backbone.js/Marionette.js中的路由-没有标签、路由列表和子路由器

BackboneJS-路由器问题-如何获得干净的URL';s

我试图将pushState设置为true,如下

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>

但所有这些都不适合我:(请大家帮帮我。

这对我有效。

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