Reloading the page gives wrong GET request with AngularJS HTML5 mode

前端 未结 24 3254
慢半拍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 01:59

    IIS URL Rewrite Rule to prevent 404 error after page refresh in html5mode

    For angular running under IIS on Windows

    
      
        
          
          
            
            
          
          
        
      
    
    

    NodeJS / ExpressJS Routes to prevent 404 error after page refresh in html5mode

    For angular running under Node/Express

    var express = require('express');
    var path = require('path');
    var router = express.Router();
    
    // serve angular front end files from root path
    router.use('/', express.static('app', { redirect: false }));
    
    // rewrite virtual urls to angular app to enable refreshing of internal pages
    router.get('*', function (req, res, next) {
        res.sendFile(path.resolve('app/index.html'));
    });
    
    module.exports = router;
    

    More info at: AngularJS - Enable HTML5 Mode Page Refresh Without 404 Errors in NodeJS and IIS

提交回复
热议问题