Angular 2 rc4不能通过在地址栏输入url转到页面 [英] Angular 2 rc4 can not go to page by typing the url to the address bar

查看:158
本文介绍了Angular 2 rc4不能通过在地址栏输入url转到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将项目更新为rc 4版本,并且出现了问题.

I 've just update my project to version rc 4 and got the problem.

当我使用systemjs来配置我的项目时,一切正常.

When I use the systemjs to config my project, everything is ok.

当我使用webpack运行项目时(我正在使用 angular2-webpack-starter )项目已成功运行,没有错误.我可以转到[routerLink]配置的每个链接.

When I run the project with webpack (I am using the angular2-webpack-starter ) the project was run successfully, no bugs. I can go to every link which was config by [routerLink].

但是如果我输入浏览器地址栏的URL,则使用相同的链接.没事我的应用程序未加载任何内容. 这是我的项目的一些屏幕截图:

But with the same link if I type the url to the browser's address bar. There was nothing happened. My app did not load anything. Here is some screen shot from my project:

屏幕截图

有人可以帮助我吗?我非常感谢你.

Can anyone help me? I am thank you so much.

推荐答案

这需要由您的后端服务器处理.

This needs to be handled by your back-end server.

您需要将所有请求发送到索引页面,以便Angular可以接收请求并从那里解析路由.

You need to send all requests to the index page so that Angular can pick up the request and resolve the route from there.

发生的事情是,当您访问Angular的索引(/)页面时,当您单击[routerlink]时,它假装在浏览器中更改页面(实际上对服务器没有任何作用).当您通过输入URL访问不是索引的任何页面时,就不会加载Angular应用,因此它无法在浏览器中编辑路线.通过将所有路由转发到索引,我们让Angular决定应如何处理所有路由而不是服务器的处理方式.

What's happening is when you visit your index(/) page Angular takes over and when you click on a [routerlink] it pretends to change the page in the browser (it's not actually doing anything with the server). When you visit any page that isn't the index by typing in the URL then you are not loading your Angular app and therefore it's not able to edit routes in the browser. By forwarding all routes to the index we're letting Angular decide how all routes should be handled, instead of the server.

这篇关于Angular 2 rc4不能通过在地址栏输入url转到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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