AngularJS:更改浏览器的位置URL,以阻止用户书签错误页面副歌? [英] AngularJS: Refrain from changing the browser location URL to stop user from bookmarking an error page?

查看:310
本文介绍了AngularJS:更改浏览器的位置URL,以阻止用户书签错误页面副歌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要提交一个表单,如果出了问题,我想显示错误页面,我对这个控制器和看法,但我想在浏览器的地址文本框不改变,以避免用户从书签错误页面。

I have a form that I need to submit, if something goes wrong I would like to show an error page, I have a controller and view for this but I would like for the browser location textbox not to change to avoid the user from bookmarking the error page.

所以我有一个名为页/项

So I would have a page called /Items

在用户提交,并有一个错误,所以我想显示此页面(itemsError.html)的用户,但我不想让用户书签/ ItemsError

the user submits and there was an error so I would like to show this page (itemsError.html) to the user but I don't want to allow the user to bookmark /ItemsError

如果我插件安装到routeprovider然后在浏览器地址栏会喜欢的东西/ ItemsError,并在用户可以书签的网页日后更新,但这个页面是动态网页,只应视显示表单提交的结果。

If I plugin into the routeprovider then the browser location bar is going to update with something like /ItemsError and at a later date the user could bookmark the page, but this page is a dynamic page and should only be shown depending on the result of the form submission.

什么是角上最好的支持这样的做法?

What is Angular's best practice for supporting something like this?

感谢

推荐答案

config.js

$routeProvider.when('/', {
  template: '/views/home.html',
});

的index.html

<!doctype html>
<html lang="en" ng-controller="app">
<head>
</head>
<body>
<ng-include src="page"></ng-include>
</body>
</html>

controllers.js

controller('app', ['$scope','$route',function($scope,$route) {
  $scope.$on("$routeChangeSuccess",function($currentRoute,$previousRoute){
    $scope.page = $route.current.template;
  });
}]).

这将处理您的通用布线。现在,您可以动态地交换谐音在基于逻辑的控制器。在你的榜样,如果表格没有成功完成,您的错误回调可以改变局部动态:

This will handle your general routing. Now you can dynamically swap partials in your controllers based on logic. In your example, if the form doesn't successfully complete, your error callback can just change the partial on the fly:

controller('form', ['$scope','$route',function($scope,$route) {
  $scope.submit = function(){
    something.get().$then(
       function( value ){$scope.page = '/views/successPage.html/';},
       function( error ){$scope.page = '/views/errorPage.html/';}
    )
  }
}]).

这篇关于AngularJS:更改浏览器的位置URL,以阻止用户书签错误页面副歌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆