GoDaddy上的路由链接angular 4错误

Men*_*Gil 1 routing angular

我的网站有问题。它是用Angular 4编写的。

问题出在这里:我只能使用以下链接:www.mywebsite.com(例如,如果使用):www.mywebsite.com/page、www.mywebsite.com/page1这会给我一个错误。意思是,如果我先去mywebsite.com然后单击链接,那么它将显示正确的页面。但是,如果我将浏览器放入mywebsite.com/page,那么它将显示错误页面。

我正在使用标准的角度路由器并将其托管在GoDaddy上。知道为什么会这样吗?

Men*_*Gil 6

好的,我找到了一个解决方案-此处:https : //www.godaddy.com/community/VPS-Dedicated-Servers/Using-Angular-2-routing-on-Linux-Hosting-with-cPanel/mp/33959 #M1119

简而言之,您需要将此代码添加到.htaccess文件中:

<IfModule mod_rewrite.c>
  Options Indexes FollowSymLinks
  RewriteEngine On
  RewriteBase /myappdirectory/
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

其中myappdirectory是托管服务上该应用程序所在的主目录