我使用这个库在javascript单页应用程序上执行URL回退到index.html:https://github.com/bripkens/connect-history-api-fallback
此库适用于以下路线:
mysite.commysite.com/foomysite.com/bar
然而,我似乎必须自定义重写方法来处理URLS,例如:
mysite.com/foo/bar
我已经在github上提出了一个问题,并从作者那里得到了一些反馈,但我无法真正做到这一点,因为我的regex技能绝对是shiz。
更新1(2016-01-13 15:27):
下面是重写规则的例子。正如你所看到的,我对这些规则非常重复,因为我对每一条路线都有这些规则,比如mysite.com/bar或mysite.com/foo。更糟糕的是,这无法处理我有mysite.com/{foo}/edit的场景,其中foo显然是一个变量:
from: /^/foo/css/.*$/,
to: function (context) {
return context.parsedUrl.pathname.replace('/foo', '');
}
},
{
from: /^/bar/js/.*$/,
to: function (context) {
return context.parsedUrl.pathname.replace('/bar', '');
}
},
我今天发现连接历史api回退没有任何问题。我只是在index.html文件和requirejs的baseUrl配置中都有错误的URL路径。对这些问题的回答让我得出了结论:mod_rewrite to index.html打破了深度URL 的相对路径