Angular2/无法获取/page_name [英] Angular2 / Cannot GET /page_name

查看:54
本文介绍了Angular2/无法获取/page_name的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了angular2应用程序,并配置了路由.通过浏览器可以正常打开页面.但是,当我尝试通过GET请求(例如邮递员)时,收到"Cannot GET/page_name"消息.错误404.如果我对主网址(localhost:4200)运行GET请求,则index.html中的html内容会获得OK状态

I have created angular2 application, configures with routes. Pages open fine via browser. However when I try GET request via (e.g. postman) I get "Cannot GET /page_name" message. Error 404. If I run GET request against main url (localhost:4200) I get OK status with the html contents from index.html

我想念什么吗?

谢谢您的时间.

更新:

为问题提供更多背景信息.我已经实现了带有隐式授予的OAuth2身份验证.一旦使用隐式授权生成了经过身份验证的OAuth2令牌,则输入用户名/密码以针对Spring(即后端)进行身份验证.问题在于隐式授予将URL(redirect_uri)中的令牌表示为哈希片段(锚)#".因此,必须在客户端解析该值.我的redirect_uri设置为返回角度应用程序登录页面( http://localhost:4200/login )网址中带有令牌.并且重定向失败并显示404.我直接通过邮递员进行了测试,以访问 http://localhost:4200/login 我也遇到了404错误.访问 http://localhost:4200 返回index.html源html.

To give more context to the question. I have implemented OAuth2 authentication with implicit grant. The enters user/password for authentication against Spring (that's the backend) once it's authenticated OAuth2 token is generated with implicit grant. The problem is that implicit grant represents the token in URL (redirect_uri) as hash fragment (anchor) "#". As such the value must be parsed on client side. My redirect_uri is set to go back to the angular application login page (http://localhost:4200/login) with the token in the URL. And the redirect it fails with 404. I tested directly to access http://localhost:4200/login via postman and I got same 404 error. Accessing http://localhost:4200 returns index.html source html.

推荐答案

Angular在单页应用程序领域中运行,因此本质上,当您运行angular应用程序时,访问该应用程序的唯一方法是进入索引页,在index.html的base_ref属性中指定.

Angular operates in the realm of single page applications so essentially when you run an angular application, the only way to access the application is to go the the index page which is specified in the base_ref attribute in index.html.

查询索引页面时,可以使用特定的路由配置来路由应用程序.同样,主页是从index.html加载的,一旦您进入了应用程序本身,就可以从那里进行路由.

When you query to the index page, then you can route the application using your specific configuration of routes. Again, the main page is loaded from index.html and once you are on the application itself you can route from there on out.

如果您想通过Postman查询应用程序中的特定页面,则可以随请求发送一些URL参数,并在应用程序的主页上解析URL参数,并使用类似的方法将用户发送到该页面这个:

If you want to query to a particular page on your application via Postman you could send some URL parameters with your request and on your main page of your application, parse out the URL parameters and send your user to the page with something like this:

this.router.navigate(['/example'])

由于您是在本地主机上运行此程序,因此可以访问浏览器中的页面,但无法使用类似

Since you're running this on your localhost, you will be able to reach the page in the browser but you won't be able to do a GET from Postman with something like http://localhost:4200/example unless you do some internal routing with your application.

这篇关于Angular2/无法获取/page_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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