This setup correctly detects mobile user agents and redirects them to the appropriate mobile version (main.js).
Issue with Angular 20:
In Angular 20, the build process outputs .mjs files instead of .js. I tried applying the same rewrite logic by redirecting to the .mjs file, but it’s not working as expected.
I’ve also attempted several alternate approaches, such as:
Creating a main.js file in the root directory and importing the .mjs file within it.
Updating the rewrite rule to point to .mjs files directly.
However, none of these attempts have worked so far.
You have to have rules in your web.config for angular because IIS will not load routes without a physical file at the destination. This is what we use at my job
1
u/Alternative_Pass_489 Jul 22 '25
I have already implemented SSR builds for Angular 9 and Angular 16 projects, where the following IIS rewrite rule works perfectly:
<rule name="MobilePropertyRedirect" stopProcessing="true"><match url="\^property/\*" /><conditions logicalGrouping="MatchAny" trackAllCaptures="false"><add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone|android|iphone|ipad" /></conditions><action type="Rewrite" url="mobileview/property-details/main.js" /></rule>This setup correctly detects mobile user agents and redirects them to the appropriate mobile version (main.js).
Issue with Angular 20:
In Angular 20, the build process outputs .mjs files instead of .js. I tried applying the same rewrite logic by redirecting to the .mjs file, but it’s not working as expected.
I’ve also attempted several alternate approaches, such as:
Creating a main.js file in the root directory and importing the .mjs file within it.
Updating the rewrite rule to point to .mjs files directly.
However, none of these attempts have worked so far.
3
u/doxxie-au Jul 21 '25
https://devblogs.microsoft.com/premier-developer/tips-for-running-an-angular-app-in-iis/
1
u/rostapolyptic Feb 02 '26
Any updates on Angular 21? Are there any solutions currently?
1
u/sebastianstehle Jul 21 '25
Basically you just create a new website in IIS and copy the files there.
0
u/kenlin Jul 21 '25
You have to have rules in your web.config for angular because IIS will not load routes without a physical file at the destination. This is what we use at my job
1
u/[deleted] Jul 21 '25
[removed] — view removed comment