当用户丢失密码时,会通过网址向其帐户发送电子邮件。我想只有在url有参数的情况下才会加载控制重置密码的页面。我正在使用Angular。
例如:
如果用户转到http://example.com/reset_password/A232Ddade
通常会加载reset_password / reset_password.html页面
但是
如果用户转到http://example.com/reset_password/ 重定向到http://example.com/index.html
另一件需要考虑的事情是,在渲染页面之前,我将使用该参数来查找将更改密码的用户。
为了实现这一点,我必须使用一些初始化函数,读取参数,如果它存在使用它或者它是否存在重定向到索引页面?像
//At the top of the controller
var init = function () {
//check if there is query in url
//and redirect if not
};
//and fire it after definition
init();
或者我可以使用ui-router模块吗?
感谢。
答案 0 :(得分:1)
它看起来像$routeProvider
的标准用法app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/reset_password/:param', {templateUrl: 'pageToReset.html', controller: ResetLogicCtrl}).
when('/reset_password/', {templateUrl: 'index.html', controller: IndexCtrl}).
otherwise({redirectTo: '/'});
}]);
答案 1 :(得分:0)
您可以在路线上使用解决来执行此操作。拿下参数并让用户使用它,如果没有用户,或者如果param是伪值,则重定向到您想要的任何地方。这样,您的控制器就可以获取所需的数据,或者重定向。