Angular-cli: ng eject breaks routing

Created on 16 Mar 2017  路  4Comments  路  Source: angular/angular-cli

If I try routing before ejecting the webpack, it works as expected. As soon as you do ng eject, the application does compiles and runs, but router does not work. The first call is routed properly, but if you try to refresh or navigate to other route, the application returns CANNOT /GET route.

Any suggestions?

broken bufix

Most helpful comment

Struggling with the same problem, but found a solution on a similar problem with React. Add the following configuration to your webpack.config.js

"devServer": {
  "historyApiFallback": true
},

All 4 comments

It's related to the webpack dev server configuration. It needs to be using fallback option like we do on https://github.com/angular/angular-cli/blob/master/packages/@angular/cli/tasks/serve.ts#L138-L142 but the npm start script on eject doesn't take that into account.

I also noticed "ng eject" does not include "webpack" as a devDependency in package.json.
~npm build and ~yarn build fail since "webpack" cannot be resolved.

Build command found in package.json's scripts
"build": "webpack",

Struggling with the same problem, but found a solution on a similar problem with React. Add the following configuration to your webpack.config.js

"devServer": {
  "historyApiFallback": true
},

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajjejosefsson picture rajjejosefsson  路  3Comments

delasteve picture delasteve  路  3Comments

hartjo picture hartjo  路  3Comments

ericel picture ericel  路  3Comments

jmurphzyo picture jmurphzyo  路  3Comments