preboot / angular-webpack

A complete, yet simple, starter for Angular v2+ using webpack
MIT License
1.29k stars 561 forks source link

Error Router on server #319

Closed ramdannur closed 7 years ago

ramdannur commented 7 years ago

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

example:

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.

strictd commented 7 years ago

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;
    }
}
ramdannur commented 7 years ago

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 / ... . . . . . . . . . .

ramdannur commented 7 years ago

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