[英]Angular JS - full page reload if not matching route
I'm looking for a clean way to do a full page reload if not matching route. 我正在寻找一种干净的方法,以在路由不匹配时重新加载整个页面。
Angular docs page is currently doing a similar thing. Angular文档页面当前正在做类似的事情。 When you click on the stuff on the sidebar, it makes an ajax call.
当您单击侧栏上的内容时,它将发出ajax调用。 But, when clicking on any of the top menu, it does a full page reload.
但是,当单击任何顶部菜单时,它会重新加载整个页面。
I guess one possible way is to listen to a route change event, test all the route regexes against the current url and calls the $window.location.reload() if not matching. 我猜一种可能的方法是侦听路由更改事件,针对当前url测试所有路由正则表达式,如果不匹配,则调用$ window.location.reload()。 But I'm hoping for a cleaner way..
但我希望有一种更清洁的方法。
Thanks! 谢谢!
Use $routeProvider 使用$ routeProvider
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {
redirectTo: '/home'
})
.when('/home', {
templateUrl: 'partials/home',
controller: 'HomeCtrl'
})
.otherwise({
redirectTo: '/somePage'
});
}];
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.