I have a project Using Spring and Angular JS. When I attempt to remove the ungly "/#/", I followed the following tutorial:
in my index html file:
<base href="/">
in my AngularJS config:
app.config(
function ($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise("/");
.state('business', {
abstract: true,
url: "/",
templateUrl: "business/businessView"
})
.state('business.intro1', {
url: "/intro1",
templateUrl: "business/page-1",
})
$locationProvider.html5Mode({enabled: true)};
}
);
So In order to support resource, I added following JAVA code to my spring controller
@RequestMapping(value = "/{[path:[^\\.]*}")
public String redirect() {
return "forward:/";
}
@RequestMapping("/business/**")
public String returnBusinessHtml() {
String uri = request.getRequestURI().substring(request.getContextPath().length());
return uri;
}
and successfully avoided 404 issue when directly access URL.
Everything is looking good for now, however, when I add a URL to the abstract controller of angularJS:
.state('business', {
abstract: true,
url: "/business",
templateUrl: "business/businessView"
})
the 404 issue came out again when I tried to access localhost:8080/business/intro1
.
If I try other page like localhost:8080/businessLanding
, It's OK.
Maybe the issue came out from @RequestMapping(value = "/{[path:[^\\.]*}")
this regular expression? Please help, thanks!