Pasha
Pasha

Reputation: 33

Angular url problems on IIS

I deployed my dot net core 3.1 api and angular 9 app into IIS. Api works well. When I hit the url for login it works well and took me into my Dashboard. http://192.168.15.12:8020/ePortal/home.

After that when I click on my other component say I wants to go to Color. When I click on Color the urls is http://192.168.15.12:8020/home/color-details instead of http://192.168.15.12:8020/ePortal/home/color-details that's why it shows 404(not found) error.

I've build the production using ng build --prod --base-href /ePortal/ and also add an web.config to rewrite the url

<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="/ePortal/" />
        <!--<action type="Rewrite" url="/" /> /ePortal/-->
      </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>

I can't identify the problem. Help please

Upvotes: 2

Views: 432

Answers (2)

Dako patel
Dako patel

Reputation: 920

Solutation

you can not redirect different path dir into angular,so you need to add custom for it

Example :

<a href="home/color-details">Color</a>

Upvotes: 0

Shajir Haider
Shajir Haider

Reputation: 36

It is an angular routing issue. You are using relative path but you need to use absolute pathing for this. try add "/" before your routerlink.

Example: instead of routerLink = "color" use routerLink = "/color"

Update

use this

<a mat-list-item href="color-details">Color</a>

Upvotes: 2

Related Questions