0

I am deploying an Angular app on an IIS server.

The web is displayed correctly, but when I refresh the browser it gives me a 404/500 (depends on base attribute setting and app.config) error.

In my index.html I have:

<base href = "/">

And my web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="true" />
          <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="index.html" />
              </rule>
            </rules>
          </rewrite>
            <!--<defaultDocument>
            <files>
            <remove value="index.html" />
            <add value="index.html" />
            </files>
            </defaultDocument>-->  
    </system.webServer>
</configuration>

When in the browser I call the path, it looks correctly:

http://miweb.es/WebApp/index.html

In the angular router I have goes it to redirect me and it does well to this route:

http://miweb.es/WebApp/index.html/download

But, at this moment if I browser refresh it gives me the error 404/500 (depends on base attribute setting and app.config).

What am I doing wrong ?, thanks

1 Answer 1

1

In your root routing file put { useHash: true }

@NgModule({
  imports: [RouterModule.forRoot(routes, { useHash: true })],
  exports: [RouterModule]
})
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I did change it, but it did not work for me, but I will try again maybe I have got a mistake, thanks
Before I tried but I did not get it, now it has worked perfectly, thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.