Javascript 向URL添加参数时阻止路由解释
在我的AngularJS应用程序中,我有以下路由机制:Javascript 向URL添加参数时阻止路由解释,javascript,angularjs,Javascript,Angularjs,在我的AngularJS应用程序中,我有以下路由机制: $routeProvider.when('/questions', route.resolve('questions', 'questions/', 'questions', 'overvie
$routeProvider.when('/questions',
route.resolve('questions',
'questions/',
'questions',
'overview',
access.authorizedAccess))
这是正确的,点击像domain.com/app/#/questions
这样的URL加载正确的控制器和模板
我想做的是可以选择在不触发页面重新加载的情况下向当前URL添加参数(基本上是重新解释URL)。我现在的问题是,通过执行window.location.hash='#/questions?query=test'代码>重新解释路由,导致页面重新加载
我试图做的是:
$rootScope.$on("$locationChangeStart", function (event, next, current) {
if (next.indexOf('?') > -1)
event.preventDefault();
});
这确实不会触发路由重新解释,但它会从我的哈希中删除参数,将其返回到'/questions'
在初始化$routeProvider
中的路由时,是否可以尝试重新加载搜索:false
选项。请参阅文档