0

I know there have been several similar posts and I have tried all recommendations in those posts with no luck.

I have a single-page Angular 6 application. No backend or anything like that. I am deploying to SharePoint. Everything works as expected except for when I refresh the page. When I refresh I get the 404 Not found error.

my base tag is correct in my index.html file.

In my app.component.ts file I placed

ngOnInit() {
    this.router.navigate([''])
  }

which works perfectly locally. When I hit refresh it goes back to my "home" page.

I then tried adding in

ngOnInit() {
    this.router.navigate(['index.html'])
  }

per the recommendations on another post, which did not work.

I also tried creating a web.congif file, which was another recommendation that had success in another post.

It looks like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <defaultDocument>
        <files>
            <clear />
            <add value="index.html" />
        </files>
    </defaultDocument>
    <rewrite>
      <rules>
        <rule name="AngularJS 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="/" logRewrittenUrl="true" />
        </rule>
      </rules>
    </rewrite>
 <security>
        <requestFiltering allowDoubleEscaping="true">
            <fileExtensions>
                <add fileExtension=".json" allowed="true" />
            </fileExtensions>
        </requestFiltering>
</security>
    <directoryBrowse enabled="true" />
<staticContent>
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
</system.webServer>
</configuration>

None of these have worked when deployed.

Any ideas? I would greatly appreciate it!

0 Answers0