AngularJS and Spring MVC with nested route -


i've done lot of research subject , haven't found correct or specific answer, i'm asking here before opening jira ticket on spring mvc project.

my application built spring mvc (with spring boot) backend , angularjs 1.x on front end. have html5mode activated (so, no # used, plain url http://podcast.dk.lan/podcasts/123/items/456/player).

i have 1 @controller route in back-end redirecting "/" request index.html. others routes handled @restcontroller , works json (on "/api" or "/system").

i've searched right way map angularjs routes index.html of application without breaking other parts of back-end resolvers (resource example).

i've tried following elements :

@controller public class homecontroller {        @requestmapping(value = "/{.*}")     private string home() {     return "forward:/";     } } 

it's not working because, if try access directly nested url on front-end (like /podcasts/1/items/1 ), url not caught request mapping regex.

@controller public class homecontroller {        @requestmapping(value = "/**/{.*}")     private string home() {     return "forward:/";     } } 

this configuration lead stackoverflow error because url redirect itself...

recently, in tutorial spring-security , angularjs, used following pattern:

@controller public class homecontroller {    @requestmapping(value = "/{[path:[^\\.]*}")     private string home() {     return "forward:/";     } } 

this pattern excludes resources (css , js) excluding url . (dot) in url. unfortunately it's not working nested routes... returning 404 error.

so, app backend linked route front-end, because have hard-code angularjs route use in front-end request mapping value :

@controller public class homecontroller {      @requestmapping(value = {"", "items", "podcasts", "podcasts/**", "player", "podcast-creation", "download", "stats"})     private string home() {         return "forward:/";     } } 

i think (and hope) there better solution redirect "not mapped url backend mapping" specific method this.

all code of project hosted on github (if want see more code) @ davinkevin/podcast-server

thanks help

i don't know if best solution or not, simple , worked , believe should able handle case.

the main goal here make backend forward requests supposed resolved angular routes (in other words, no real resource uris in backend) root /, when browser loads index , angular app again, angular can resolve route on client side. if have well-known , reserved prefix angular routes (ie: /fe [short frontend]), can use request mapping pattern /fe/** returns forward:/.

you need make sure angular routes start /fe/ , there no static resources in fe folder or no other request mappings start prefix.

@controller public class homecontroller {      @requestmapping(value = "/fe/**")     public string redirect() {         return "forward:/";     } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -