preboot/angular-webpack

Error Router on server

ramdannur opened this issue · 3 comments

When I've finished building the project for production and put it into a server, the router is not working like it should.

example:

  • Lite Server
    localhost: 4200 / members / detail -> work
    localhost: 4200 / members -> work

  • Nginx Server
    localhost: 80 / members / detail -> not working (not found)
    localhost: 80 / members -> work

note : When I access the index.html at the root of the project, routers still work as long as I did not reload that browser.

I think it was error because the server just read the directory did not read the rules of the router.

it's due to not having url redirection correct on your server.. Maybe this block will help you

server {
    listen 80;
    server_name my_server_name;
    root /projects/angular2/myproject/dist;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

ty, that configuration is work, but how to configure server with multiple angular project (dynamically) , like this.

localhost / site_a / ...
localhost / site_b / ...
localhost / site_c / ...
. . . . .
. . . . .

finally i found the solution, this configuration is work for me.

server {
        listen       80 default_server;
        server_name  localhost;
        index  index.html index.htm;

	location ~ ^(/[^/]+){
            root   html;
	    index  index.html index.htm;
            try_files $uri $uri/ /$1/index.html;
        }
}

thanks for participation