AngularJS重定向没有推历史记录状态
我的工作,有一个包罗万象的路线的AngularJS应用程序(例如,。当('/:塞',{...)
),这是要支持从previous旧版网址的格式(无棱角)版本的应用程序。响应该抓的所有尝试拉动相关的对象,并且,如果没有找到的控制器,使用 $ location.path
方法重定向到一个404页。此工程在获得用户到404页,但是当用户点击早在他们的浏览器需要他们重新回到了他们被迫到404页摆在首位的页面,他们最终是无法逃脱的怪圈。
I'm working on an AngularJS app that has a catch all route (eg, .when('/:slug', {...)
) which is necessary to support legacy url formats from a previous (non-angular) version of the app. The controller that responds to the catch all tries pulling a related object, and, if not found, redirects to a 404 page using the $location.path
method. This works at getting the user to the 404 page, but when the user hits back in their browser it takes them back to the page that forced them to the 404 page in the first place and they end up being unable to escape the cycle.
我的问题是,如果有1),用于处理这种情况下一个更好的模式,或者2)如果有一种方式来重新路由不会强制在浏览器历史记录推入状态的用户?
My question is if there is 1) a better pattern for handling this situation, or 2) if there is a way to reroute the user that doesn't force a history push state in the browser?
您可以更改URL,而不添加到历史状态,发现的这里的替换法的。这实际上是与调用HTML5的history.replaceState()。
You can change the url without adding to the history state, found here under "Replace Method". This is effectively the same as calling HTML5's history.replaceState().
$location.path('/someNewPath').replace();
我还没有发现有可能改变观点不改变网址。唯一的方法来改变看法,我发现,是改变位置路径。
I haven't found that it's possible to change the view without changing the url. The only method to change the view, that I've found, is to change the location path.