[英]Prevent route interpretation when adding parameters to URL
在我的AngularJS应用程序中,我有以下路由机制:
$routeProvider.when('/questions',
route.resolve('questions',
'questions/',
'questions',
'overview',
access.authorizedAccess))
这可以正常工作,点击像domain.com/app/#/questions
这样的URL加载正确的控制器和模板。
我想要做的是可以选择将参数添加到当前URL而不会触发页面重新加载(基本上重新解释URL)。 我现在window.location.hash = '#/questions?query=test';
是通过做window.location.hash = '#/questions?query=test';
重新解释路由导致页面重新加载。
我试图做的是这样的:
$rootScope.$on("$locationChangeStart", function (event, next, current) {
if (next.indexOf('?') > -1)
event.preventDefault();
});
这确实不会触发路由重新解释,但它会从我的哈希中删除参数,将其转回'/questions'
。
您可以在$routeProvider
中初始化路由期间尝试选项reloadOnSearch:false
。 请参阅此处的文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.