[英]Angular 4 routing doesn't work on prod
I'm developing an angular 4 web app, and did routing like so: 我正在开发一个angular 4 Web应用程序,并做了如下路由:
const routes: Routes = [
{ path: '', redirectTo: "raids", pathMatch: 'full' },
{
path: 'raids',
component: RaidsContainerComponent
},
{
path: 'gyms',
component: GymsContainerComponent
},
{
path: 'raid/:rid',
component: RaidDetailsComponent
},
{
path: 'user',
component: UsersContainerComponent
},
{
path: 'register',
component: RegisterComponent
},
{ path: '**', redirectTo: "raids", pathMatch: 'full' }
];
when i'm on local host and I write in the url line localhost/raids it gets me to RaidsContainerComponent as it should, but when I do the same on production after I've published the app, I get: 当我在本地主机上并且在url行localhost / raids中编写它时,它会像应该的那样将我带到RaidsContainerComponent,但是当我发布该应用程序后在生产环境中进行同样的操作时,我得到:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. 您要查找的资源已被删除,名称已更改或暂时不可用。
How can I fix it? 我该如何解决?
OK I've figured it out, in order to publish my site to azure i had to make web.config file: 好的,我已经弄清楚了,为了将我的网站发布到天蓝色,我必须制作web.config文件:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
</staticContent>
</system.webServer>
<system.webServer>
<rewrite>
<rules>
<rule name="angular cli routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
but ng-build didn't add it to the dist file so i had to add it manually to the ftp server, now its working. 但是ng-build没有将其添加到dist文件,因此我不得不将其手动添加到ftp服务器,现在可以正常工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.