我有我的服务器后端,这是调用从客户端X(可点击链接)与HTTP GET请求此客户端发送我的值作为RequestHeader,我需要获得这些值(头),并将其发送到我的前端(角度),最重要的事情是获得这些值,并继续我的工作流程。
下图说明了我的工作流程

这是我的java代码(spring控制器)
private static final String NG_REDIRECT_URL= "http://localhost:4200";
@GetMapping(value = "/server-core")
public RedirectView requestHandler(HttpServletRequest request, HttpServletResponse response,
@RequestHeader(value = "user_id", required = true) String userId,
@RequestHeader(value = "login", required = true) String login) throws IOException {
return new RedirectView(NG_REDIRECT_URL, true);
}发布于 2021-01-26 13:45:24
您需要将这些值作为查询参数添加到angular的url中,并且需要在下面的帮助下在app.component.ts中获取这些参数,并对这些值进行操作
ngOnInit() {
const url = window.location.href;
if (url.includes('?')) {
const httpParams = new HttpParams({ fromString: url.split('?')[1] });
const token = httpParams.get("token");
//Here you will have you operations and you navigation with the parameters
//this.router.navigate(['/home']);
} else {
//Here you will have your actual redirection
}
}并避免在路由模块中使用空路径重定向(例如,App.route-module.ts)在app.component.ts中手动导航到页面的.Try
我想这会帮助你..。
https://stackoverflow.com/questions/65873764
复制相似问题