告诉 Angular Js 忽略特定路由

编程入门 行业动态 更新时间:2024-10-28 17:28:12
本文介绍了告诉 Angular Js 忽略特定路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我已经在 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/guide/$location

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

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

更多推荐

[db:关键词]

本文发布于:2023-04-22 07:09:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1016805.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   Angular   Js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!