.Net Core with Angular 4 : 404 error when I refresh the browser

允我心安 提交于 2019-12-06 05:26:31

In back-end (server side) just map all (404) error/unrecognized requests to your index (which includes all angular build scripts).then it returns the index. In front-end, u can get what u need.It maps to the page which u need.

eg:- In spring Boot back-end this is an example answer

I had the same problem when refreshing the browser on a route like: /users I fixed it by creating a folder called: users and inside a file: index.html

<!<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>redirect users</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script>
        window.location.href = 'http://my-server:4200/';
    </script>
</head>
<body>    
</body>
</html>

other solutions that i have read:

1) make your server redirect to index.html on a 404 error.

2) make your apache or iis add /index.html at the end of every route path

Routed apps must fallback to index.html so please look at this link and add config for IIS if that is what you are using,or edit your config here

<action type="Rewrite" url="/index.html" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!