繁体   English   中英

当我转到mydomain.com/search时,Angular 2应用已部署并抛出404

[英]Angular 2 app deployed and throws a 404 when I go to mydomain.com/search

我定义了一些路线。 这是一个片段:

const appRoutes: Routes = [
  {
    path: '',
    component: HomeComponent
  },
  {
    path: 'search',
    component: SearchComponent
  }
]

我的应用程序现在已经部署完毕,但是由于使用了404,因此无法转到直接路径,例如mydomain.com/search 。但是,我可以转到mydomain.com/ ,然后单击指向/search的链接。从主页。 那很好。

我正在使用apache。 如何解决此404问题,以便可以通过显示搜索页面转到mydomain.com/search并使它正常工作?

我知道有一种使用哈希定位策略来做到这一点的方法,但是我很想知道在apache服务器上做到这一点的方法。

谢谢!

添加到.htaccess文件或httpd.conf

<IfModule mod_rewrite.c>
 RewriteEngine On RewriteBase /
 RewriteRule ^index\.html$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f 
 RewriteCond %{REQUEST_FILENAME} !-d 
 RewriteRule . /index.html [L] 
</IfModule>

需要在httpd.conf中的目录中添加AllowOverride选项

这里/ var / www / html是我项目的根

将.htaccess文件添加到您的项目

<Directory /var/www/html/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM