AngularJS - 如何在整个页面加载时进行重定向? [英] AngularJS - How can I do a redirect with a full page load?

查看:20
本文介绍了AngularJS - 如何在整个页面加载时进行重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个重新加载整个页面的重定向,以便在页面加载时刷新来自我的网络服务器的 cookie.window.location = "/#/Next"window.location.href = "/#/Next" 不起作用,它们执行的 Angular 路由不访问服务器.

I want to do a redirect that does a full page reload so that the cookies from my web server are refreshed when the page loads. window.location = "/#/Next" and window.location.href = "/#/Next" don't work, they do an Angular route which does not hit the server.

在 Angular 控制器中发出完整服务器请求的正确方法是什么?

What is the correct way to make a full server request within an Angular controller?

推荐答案

对于<a>标签:

For <a> tags:

您需要将 target="_self" 粘贴在您的 <a> 标签上

You need to stick target="_self" on your <a> tag

AngularJS 会执行完整页面重新加载的三种情况:

There are three cases where AngularJS will perform a full page reload:

  • 包含目标元素的链接
    示例:<a href="/ext/link?a=b" target="_self">link</a>
  • 指向不同域的绝对链接
    示例:<a href="http://angularjs.org/">link</a>
  • 以/"开头的链接在定义 base 时指向不同的基本路径
    示例:<a href="/not-my-base/link">link</a>

使用 javascript:

$location 服务只允许您更改 URL;它不允许您重新加载页面.当您需要更改 URL 并重新加载页面或导航到不同的页面时,请使用较低级别的 API:$window.location.href.

The $location service allows you to change only the URL; it does not allow you to reload the page. When you need to change the URL and reload the page or navigate to a different page, please use a lower level API: $window.location.href.

见:

这篇关于AngularJS - 如何在整个页面加载时进行重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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