3

すべてのリンクを変換し、そこからexample.com/actionバックボーンexample.com/index.html#actionルーターによって解析されます。

ただし、私の新しいページsignup/:inviteAuthHash(例signup/9d519a2005b3dac8802d8e9e416239a1)は機能していません。レンダリングするのはmyだけindex.htmlで、ルーターのブレークポイントはどれも満たされていません。

.htaccess:

# not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# example.com/home => example.com/index.html#home
RewriteRule ^(.+)$ index.html#$1 [L,QSA]

router.js

var AppRouter = Backbone.Router.extend( {
    routes : {
        /* PAGES */
        // beta
        'request_invite' : 'request_invite',
        'signup/:inviteAuthHash' : 'signup',

        // Default
        '*actions' : 'defaultAction'
    },

    /* PAGES */
    // eta
    request_invite : function() {
        new BetaLayout;
        new RequestInviteView;
    },
    signup : function(inviteAuthHash) {
        // validate auth hash
        if(!InviteRequest.isValidInviteAuthHash(inviteAuthHash))
            return this.defaultAction();
        else {
            new BetaLayout;
            new SignupView(SignupView);
        }
    },

    // Default
    defaultAction : function(actions) {
        app_router.navigate('request_invite');
        this.request_invite();
    }
});

var initialize = function() {
    app_router = new AppRouter;

    $('a').live('click', function() {
        var href = $(this).attr('href');

        // only navigate to real links
        if(href == undefined)
            return;

        // open in new window?
        if($(this).prop('target') == '_blank')
            return true;

        app_router.navigate(href, {trigger: true});

        return false;
    });

    Backbone.history.start({pushState: true});
};
return {
    initialize : initialize
};
4

2 に答える 2

2

代わりにこの.htaccessを試すことができますか?

# not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# example.com/home => example.com/index.html#home
RewriteRule (?!^index\.html)^(.+)$ /index.html#$1 [L,NC,R,NE]
于 2012-06-12T14:01:11.217 に答える
0

私の意見では、あなたの問題に対する別のより良い解決策があると思います。それは、pushStateの使用です。

だからあなたがすることは

  1. サーバー構成を変更して、アセットを除くexample.comのすべてのURLが実際にindex.htmlをレンダリングするようにします(私のapacheの知識は錆びていますが、難しいことではありません)。
  2. Backbone.history.startへの呼び出しを変更してpushstateを有効にし、ルートを指定します。、BackboneのドキュメントBackbone.history.start({pushState: true, root: "/"})を参照してください。

pushstateをサポートするブラウザでは、URLは正常に表示され、すべてが機能します。古いブラウザでは、バックボーンが自動的にハッシュ付きのURLに変換します。

于 2012-06-14T08:20:15.267 に答える