告诉 Angular Js 忽略特定路由 [英] Telling Angular Js to ignore a specific route

查看:24
本文介绍了告诉 Angular Js 忽略特定路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Angular 中设置了我的路由并且一切正常:

I have set up my routing in Angular and all works fine:

$locationProvider.html5Mode(true);
$routeProvider.
      when('/', { templateUrl: '/Home/Index' }).
      when('/User', { templateUrl: '/User/Index' });

但是,我现在有一个锚标记用作注销按钮,它只会将用户重定向到/User/Logout,然后注销会将用户注销并将其重定向到登录页面.所以我想要的是 angular js 忽略这个特定的路由并允许它进行正常的 http 重定向.这看起来应该很容易,但我一直无法找到解决问题的方法.

However I now have an anchor tag to work as a logout button which will just redirect the user to /User/Logout, and logout will then log the user out and redirect them to the login page. So what I want is for angular js to just ignore this specific route and allow it to do a normal http redirect. This seems like something that should be really easy but I haven't been able to find a solution to the problem.

我知道我可以做一个点击事件并在点击事件中做一个 window.location 更改,但这似乎是一种非常hacky的方式.

I know I could do a click event and do a window.location change in the click event but that seems like a really hacky way to do it.

推荐答案

在您的锚点中指定 target="_self",以便 angularjs 不会重写 URL.请参阅此处的讨论:http://docs.angularjs.org/guide/$location

specify target="_self" in your anchors, so that angularjs does not rewrite URLs. See the discussion here: http://docs.angularjs.org/guide/$location

这篇关于告诉 Angular Js 忽略特定路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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