Spring Boot with AngularJS html5Mode

后端 未结 9 2302
长发绾君心
长发绾君心 2020-11-27 04:35

I start my web application with spring boot. It use a simple main class to start an embedded tomcat server:

@Configuration
@EnableAutoConfiguration
@Componen         


        
9条回答
  •  没有蜡笔的小新
    2020-11-27 04:55

    1- first you create new Controller then copy and paste simple below code

    @Controller
    public class viewController {
    
     @RequestMapping(value = "/**/{[path:[^\\.]*}")
     public String redirect() {
        // Forward to home page so that route is preserved.
        return "forward:/";
     }
    
    }
    

    3- remove 2 below item from angular app

    $locationProvider.hashPrefix('!');
    $urlRouterProvider.otherwise("/");
    

    2- in angular application you must add $locationProvider.html5Mode(true); to app route

    3- Don't forget to place the base tag before any http request in your index.html file

    
     /* Or whatever your base path is */
    
    //call every http request for style and other 
    ...
    
    

    it's work fine for me

提交回复
热议问题