【发布时间】:2016-03-09 07:45:36
【问题描述】:
我想设置由 angular.js 路由的可访问和可收藏的 URL。
该应用程序只是整个网站的一部分,可通过http://example.com/application/访问
/application/ 之后的都是路由参数。
现在我想要一个可以通过以下方式访问的 URL
http://example.com/application/#/filter1/filter2/filter3/
^ hashbang here
或
http://example.com/application/filter1/filter2/filter3/
^ no hashbang here
我希望 angular.js 将我的路由参数传递给我的应用程序,但我却通过 .otherwise 路由。
基本路线设置
$locationProvider.html5Mode(true); // this requires base-tag to be set in dom,
// but doesnt work for me
$routeProvider
.when('/application/:filter1/:filter2/:filter3', {
action: 'filter',
reloadOnSearch: false
})
.otherwise({
redirectTo: '/application/' + filter1 + '/' + filter2 + '/' + filter3
});
在该应用程序的 HTML 中,我输入了 <base href="/application/" />,这似乎可以正常工作,但是在通过 .otherwise-route 后重新加载页面或重新访问它不起作用并且服务器说“找不到页面”。
当我禁用 HTML5 模式并删除 base-tag 时,它也不起作用,我会通过 .otherwise 路由
【问题讨论】:
-
您的服务器有责任在 /application/ 和 /application/filter1/filter2/filter3/ 请求上响应同一页面,而您没有在服务器端提供任何详细信息。
-
好的,但是用 hashbang 路由怎么样?也不起作用-而是采用 .otherwise-route
标签: javascript angularjs url angular-routing hashbang