M. Bhamre
M. Bhamre

Reputation: 65

angular-cli build is not supporting to other (/posts) then root path (/) directly

I have create a build for angular2 project with angular-cli using ng build and it creates dist folder. When I run build with other web server it working fine for root path (http://127.0.0.1:8887) and allow me to access other path(like /posts)through application. But when directly access the path for eg. http://127.0.0.1:8887/posts form browser, it gives me entry not found message. There is no error in console and it seems it's not loading index.html, when directly access with other then root path.

Upvotes: 1

Views: 143

Answers (2)

D. Greene
D. Greene

Reputation: 44

You may be running into the file name change. They changed one of the files that gets generated in the build process from "inline.js" to "inline.bundle.js"

Upvotes: 0

Brocco
Brocco

Reputation: 64893

You are hosting the application via a separate web server at that point. You must customize that server to serve the root application for unknown routes which will permit the application to handle the routing client-side rather than having it being handled in the server.

So if you navigate to [app root]/foo your web server should return [app root] and then the angular application will be responsible for showing the content associated with the foo route.

There are instructions on the web for configuring different web servers to handle/manage SPA (single-page application) configurations.

You do not see this issue when debugging via ng serve because the webpack-dev-server (being used under the hood) is configured to support this server-side routing to the app root.

Upvotes: 1

Related Questions