Yann92
Yann92

Reputation: 383

ionic as pwa with angular/pwa 404 not found

I have an ionic app that I use as a pwa, I have install @angular/pwa with ng add @angular/pwa then I run ionic build --prod and I upload all y www folder on my server but when I refresh a page I got 404 Not Found The requested URL was not found on this server.

Someone knows why ? I don't know which file and folder I should share with you to help so let me know if needed. Thank ou everyone

Upvotes: 1

Views: 2768

Answers (2)

Tatayoyoh
Tatayoyoh

Reputation: 21

Working well with Ionic LocationStrategy provider for app.module.ts as described here

Build your Ionic sources with ionic build --prod, and serve the generated www folder with NGINX.

NGINX default.conf configuration example :

 server {
    ...
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri /index.html?$args;
    }
    ...

NGINX's try_files directive will do the job with Ionic PWA routing. Page refresh with F5 will not display 404 anymore :)

Upvotes: 1

Todd Shelton
Todd Shelton

Reputation: 1

This may be too late for you, but I had the same trouble with my PWA. If you look in your www folder and open your index.html file you will need to make this change.

<base href="/">

to

<base href="">

If the above doesn't work you can try putting a .htaccess file in your project root directory that sends all request back to the index.html page. Just create the file .htaccess and put the below code inside the file.

DirectoryIndex index.html
ErrorDocument 404 https://in-info-web4.informatics.iupui.edu/~username/appName/

Upvotes: 0

Related Questions