Skip to content

Natural routes with path variables in spring-boot modular project does not work #68

@iwanzarembo

Description

@iwanzarembo

I followed the blog about Spring Security and Angular JS and there is a chapter about "natural" routes. Here a small quote:

the login page is specified as a route in hello.js as "/login" and this translates into "/#/login" in the actual URL (the one you see in the browser window). This is so that the JavaScript in the index.html, loaded via the root path "/", stays active on all routes.

Quote from Using "Natural" Routes

The example works great as long you are using simple routes like:

          $routeProvider.when('/', {  
            templateUrl : 'js/home/home.html',  
            controller : 'home'  
          }).when('/login', {  
            templateUrl : 'js/navigation/login.html',  
            controller : 'navigation'  
          }).otherwise('/');`  

In that you can call in your browser http://..../login and Spring (server side) will forward you to the correct page using the RequestMapping below:

    @RequestMapping(value = "/{[path:[^\\.]*}")
    public String redirect() {
      return "forward:/";
    }

Unfortunately this only works if you are not using any path variables. But I would like to use routes like:

          $routeProvider.when('/', {
            templateUrl : 'js/home/home.html',
            controller : 'home'
          }).when('/users', {
                templateUrl: 'js/usermanagement/list.html',
                controller: 'userList'
            }).when('/users/:id', {
                templateUrl: 'js/usermanagement/userDetails.html',
                controller: 'userDetails'
            }).when('/users/:id/edit', {
                  templateUrl: 'js/usermanagement/edit.html',
                  controller: 'userEdit'
            }).otherwise('/');

If I start my application and the route is used without server side redirect then I am able to navigate to http://..../users/some_id
but if I hit refresh, then I get the a 404.

I tried to fix it by adding another RequestMapping with a different value, but I could not manage it to work.

You can reproduce it by changing three files in the Modular Project, see Changes in Files via Patebin
Then do the following:

  1. start the spring-boot application and login as usual
  2. Click on the Show message via URL link
    Here you will see that the message content will show the value "link_msg" as shown in the URL.
  3. Hit refresh
    Now you will see the Whitelabel Error Page

I do not know how to fix this, but I hope you can.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions