Question

I'm working on a grails/angular application, on which angular router is set to use HTML5 History. But, to use this setting we have to declare route in the angular router AND in the grails UrlMappings.

For instance, the angular router:

angular.module('myModule',['ngRoute']).config(['$locationProvider', '$routeProvider', 
   function($locationProvider, $routeProvider) {
      $locationProvider.html5mode(true);
      $routeProvider.when('my/url', {})
                    .when('my/other/url', {}) 
   }
]);

And the UrlMappings.groovy file :

class UrlMappings {

    static mappings = {
        //Here, duplication from the angular router
        //My Single Page Angular Application is on view index 
        'my/url'(view:'/index')
        'my/other/url'(view:'/index')
    }
}

has someone a clean solution to avoid the duplication between this 2 files ?

Was it helpful?

Solution

Grails apps provide a Spring bean named grailsUrlMappingsHolder that gives programmatic access to the URL mappings defined in the application (and it's plugins). This bean is an instance of UrlMappingsHolder. You can read the URL mappings from the bean's getUrlMappings() method and construct the URLs in your angular router from this list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top