After deployment to IIS I found out that none of my routes work, Hence I researched then found this question in which says that you have to add a rewrite to web.config
, which I did and routes are working now.
Here is some of my routes that work in development mode, but in production :
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'manage', component: ManageComponent },
{ path: 'manage/products', component: ProductComponent },
{ path: 'manage/products/:action/:id', component: ProductComponent },
{ path: 'manage/companies', component: CompanyComponent },
];
And what I did in web.config
:
<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"/>
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
</conditions>
<action type="Rewrite" url="/"/>
</rule>
</rules>
</rewrite>
</system.webServer>
So what the actual problem is? The problem raises when I refresh/redirect the page. After an hour research found out that the rule I wrote in web.config
always returns index.html
and that's why I get Uncaught SyntaxError: Unexpected token <
in the following files :
inline.bundle.js:1
polyfills.bundle.js:1
styles.bundle.js:1
vendor.bundle.js:1
main.bundle.js:1
What do you suggest to fix this?
Update: By removing manage
from routes fixed the problem for routes without parameter, but the problem is still there for routes containing parameter.
After an hour research found out that the rule I wrote in web.config always returns index.html
- well, don't do that – Jaromanda X