在Cloud Foundry中部署时的角度4应用程序路由问题

时间:2018-10-28 04:58:32

标签: angular angular-ui-router angular-routing pivotal-cloud-foundry

我这里有一个独特的路由问题,我有一个角度应用程序,该应用程序在我的本地环境下运行良好,但是当该应用程序部署到云铸造厂时,路由根本无法工作(给出404)。

这是路由的代码段

import  { LocationStrategy,  PathLocationStrategy }  from  '@angular/common';
const  appRoutes:  Routes  =   [{
  path:   '',
  component:  PageNotFoundComponent
 },
 {
  path:   'contents',
  component:  ContentsComponent
 },
 {
  path:   'sidebar',
  component:  SidebarComponent
 }
];

我正在寻找这些:

路由条件:

  1. 路由而不进行散列。
  2. 直接向浏览器输入URL应该会导航到该页面。
  3. 不应显示404错误。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

def function(names,grades):
    return_list = []
    for i in range(0,len(names)):
        return_list.append( {names[i]:grades[i] }
    return_list = sorted(return_list, reverse=True)

    for i in range(0,len(a)):
        for key in a[i]:
            print str(key)+ '/'+str(a[i][key][0])

有关运输问题,请转到https://angular.io/guide/deployment

您将根据您的服务器获得解决方案

或使用节点服务器

答案 1 :(得分:0)

解决方案是将 .HTACCESS 文件与路由条件一起使用。 将应用程序部署到Cloud Foundry时,使用“ php_buildpack”作为构建包

.htaccess文件中使用的路由条件

`RewriteEngine on

RewriteCond%{REQUEST_FILENAME}!-f

RewriteCond%{REQUEST_FILENAME}!-d

不重写CSS,js和图像

RewriteCond%{REQUEST_URI}!。(?: css | js | map | jpe?g | gif | png)$ [NC]

RewriteRule ^(。*)$ /index.html?path=$1 [NC,L,QSA]`