简体   繁体   English

Angular 2在onInit中获取标题

[英]Angular 2 get headers in onInit

I'm developing on an Angular2 project and I've a problem regarding headers in http request. 我正在开发Angular2项目,并且在http请求中存在有关标头的问题。 This is my scenario: I've a main page already developed, in a project I can't work on, with a menu in which every item redirects on various pages I'm developing. 这是我的情况:我已经开发了一个主页,在一个我无法处理的项目中,它带有一个菜单,每个项目都在我正在开发的各个页面上重定向。 The main page, on every redirect call, sets a field in the header. 在每次重定向调用时,主页都会在标题中设置一个字段。 Using Explorer developer tool I can see the first call on redirect with field setted in header and the http request is something like this: 使用Explorer开发人员工具,我可以看到在标头中设置了字段的重定向上的首次调用,并且http请求是这样的:

https://myProject/main

My question is: can I get headers on onInit function of my page? 我的问题是:我可以在页面的onInit函数上获取标头吗? I tried to make an http request to https://myProject/main in onInit function but it returns 302 error. 我试图在onInit函数中对https://myProject/main发出一个http请求,但它返回302错误。 Any suggestions? 有什么建议么?

EDIT: The main page is not part of my project. 编辑:主页不是我的项目的一部分。

I think you have to look into angular routing and navigation. 我认为您必须研究角度路由和导航。

A http redirect call is not required unless the page you are trying to load is not developed within your application. 除非您尝试加载的页面未在应用程序中开发,否则不需要http重定向调用。

Angular routing and navigation reference 角路由和导航参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM