【问题标题】:app refresh when typing routes in browser address bar angular 2在浏览器地址栏中输入路由时应用刷新 Angular 2
【发布时间】:2017-10-27 21:38:16
【问题描述】:

我在 angular2 应用中定义了路线。

    const appRoute:Routes = [
  {path:'',component:LoginComponent},
  {path:'about',component:AboutComponent},
  {path:'cart',component:CartAreaComponent},
  {path:'checkout',component:CheckoutComponent},
  {path:'register',component:RegisterComponent},
  {path:'verify',component:VerifyUserComponent},
  {path:'login',redirectTo:''}
]

当我使用标签更改路线时,一切都正常工作。

但是当我尝试在浏览器地址栏中手动输入路由时。应用程序刷新并返回回家路线。

例如http://localhost:4200/verify 直接在地址栏中输入时不起作用。但如果通过应用程序中的某个链接完成,则可以工作。

请帮忙。

【问题讨论】:

  • 你能把你的完整路由器类,app.module 和 app.component 贴出来
  • 你的服务器是什么,是nglite吗?通过使用 ng 服务???或者像 nginx 、 apache 等一些 http 服务器?

标签: angular


【解决方案1】:

这可能是因为 html5history 模式。如果您不使用散列,那么您可以将服务器配置为回退到未找到请求路由的 index.html。当您手动输入地址并按回车键时会转到服务器,但是当您单击应用程序中的链接时,角度会在客户端处理它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 2013-07-04
    • 2017-02-01
    相关资源
    最近更新 更多