I want to write an SPA with AngularJS on client side and Java EE on server side. If I understand it correctly, the idea for the frontend is to create a default page (let's call it index.html) and implement routing to exchange parts of this default page. So with every request the default page is loaded and the routing logic replaces its parts depending on context path:
<!-- index.html --> <html> <body> <!-- this block is replaced depending on context --> <div ng-view></div> </body> </html> <!-- page one --> <div> <h1>Page One</h1> <a href="/specific">Some specific stuff</a> </div> <!-- page two --> <div> <h1>Page Two</h1> </div> Now, the routing logic could be something like this:
angular.module('myApp', []) .config(['$routeProvider', function ($routeProvider) { $routeProvider .when('/', {templateUrl: 'pages/pageOne.html'}) .when('/someSpecific', {templateUrl: 'pageTwo.html'}) .otherwise({redirectTo: '/'}); } ]); The question is, how do I couple this with Java EE and a Wildfly server instance? If I declare index.html as the welcome page and do nothing else, the direct calls like http://website.org/someSpecificContext will fail because no page is mapped to the path (and shouldn't be), so no page and no angular code will be loaded. If I make a redirection from every possible subpath to index.html in a servlet filter, then the path information will be lost, so every call will end in the index page. Maybe it's a silly newbie question, but I'm really stuck here and would appreciate any help.
html5Modeso all your angular paths will have a#in them and won't have any server impact at all that way. You only need to configure server if you usehtml5Modeand use pretty url's without#. Serve the templates any way you wanthtml5mode, I didn't include it for code simplicity. I will update the question to draw less attention to angularJS topic.