Angular 角度4布线不';我不在生产线上工作
我正在开发一个angular 4 web应用程序,并这样做:Angular 角度4布线不';我不在生产线上工作,angular,routing,angular-routing,angular-router,Angular,Routing,Angular Routing,Angular Router,我正在开发一个angular 4 web应用程序,并这样做: const routes: Routes = [ { path: '', redirectTo: "raids", pathMatch: 'full' }, { path: 'raids', component: RaidsContainerComponent }, { path: 'gyms', component: GymsContai
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' }
];
当我在本地主机上,并且我在url行localhost/raids中写入时,它会让我以应有的方式访问RaidsContainerComponent,但当我在发布应用程序后在生产中执行相同操作时,我会得到:
您正在查找的资源已被删除、名称已更改或暂时不可用
如何修复它?好的,我已经解决了,为了将我的网站发布到azure,我必须创建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>
但是ng build没有将其添加到dist文件中,所以我不得不手动将其添加到ftp服务器中,现在它可以工作了。这是您唯一的路由,还是您有延迟加载或其他什么?您应该在应用程序中使用路由器链接,而不是在URL栏中输入URL,@Erez已将您添加到索引中。htmlYou正在使用
PathLocationStrategy
,其中服务器需要能够返回每个URL的主应用程序代码。由Angular CLI启动的本地开发服务器确实支持此功能,这就是为什么它在开发模式下工作,但在产品中不工作的原因。@trichetriche延迟加载是什么?我对这个有点陌生,我只有这个路线。。Vikas我在我的链接中也使用了routerlink来引用这些页面,但这不是我的问题,我希望它也能用于直接url输入。Suvethanantha我做了