I have a problem with redirect my app in production mode. when I have url http://server.com/projectname/dashboard
, server response IIS error page 404. I must open app using http://server.com/projectname
and then click on link for example:
<a [routerLink]="'dashboard'">Dashboard</a>
In html i have <base href="./">
and this is my router:
const appRoutes: Routes = [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full', canActivate: [AuthGuard] },
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard]},
{ path: '400', component: ErrorComponent, canActivate: [AuthGuard] },
{ path: '401', component: ErrorComponent, canActivate: [AuthGuard] },
{ path: '404', component: ErrorComponent, canActivate: [AuthGuard],
{ path: '**', redirectTo: '/404' }
]
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
]
})
In development mode I have url http://localhost:4200/dashboard
and i should redirect. Can it be problem when in developing is url localhost:4200/dashboard and in production is server.com/appname/dashboard?
I found the cause. I must configuration fallback. Here is article about it.
I had to add web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular 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="./" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Now it works correctly and i can open arbitrary app url.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments