Reloading the page gives wrong GET request with AngularJS HTML5 mode

前端 未结 24 2981
慢半拍i
慢半拍i 2020-11-22 01:39

I want to enable HTML5 mode for my app. I have put the following code for the configuration, as shown here:

return app.config([\'$routeProvider\',\'$location         


        
24条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 02:05

    I have resolved the issue by adding below code snippet into node.js file.

    app.get("/*", function (request, response) {
        console.log('Unknown API called');
        response.redirect('/#' + request.url);
    });
    

    Note : when we refresh the page, it will look for the API instead of Angular page (Because of no # tag in URL.) . Using the above code, I am redirecting to the url with #

提交回复
热议问题