My App uses Spring Boot for backend and Angular JS for frontend.
I use Thymeleaf for the multi-language support. Thymeleaf requires all html files to be put under a folder called templates.
At the frontend, I used angular's routeProvider to redirect pages. Here is the code:
angular.
module("myapp").
config(function ($routeProvider) {
$routeProvider
.when( '/dashboard/:param1/:param2/', {
templateUrl: 'templates/pages/dashboard.html',
controller: 'dashboardController',
reloadOnSearch: false
})
.when( '/login/', {
templateUrl: 'templates/auth/login.html'
})
.otherwise({ redirectTo: '/dashboard/global/-1' });
});
At the java side, I have some ViewController code in my WebConfig.java
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
super.addViewControllers(registry);
registry.addViewController("/login").setViewName("auth/login"); //This works
registry.addViewController("/dashboard/**").setViewName("page/dashboard"); //Don't work, 404 error
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
}
The login pages works, but for dashboard, Angular gives me a 404 error.
GET http://localhost:8080/myapp/templates/pages/dashboard.html 404 (Not Found)
If I move the dashboard out of template folder, and change the templateUrl to
templateUrl: 'pages/dashboard.html',
Angular now can find and display the dashboard page, but Thymeleaf no longer works since it is out of the template folder. I've lost the multi-language ability.
I see login.html is a complete html page with the head, body; dashboard.html is a part of index.html, so it is just a big div.
I am confused on the Spring MVC and Angular routerProvider. Is possible to use ANGULARJS $routeProvider in my case? Should I only use Spring MVC since I do need Thymeleaf for the multi-language ability? Any suggestions?