如何没有Grails的urlMapping中和角路由器之间的重复 [英] How to not have duplication between grails UrlMapping and angular Router

查看:375
本文介绍了如何没有Grails的urlMapping中和角路由器之间的重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Grails /角度的应用,在其角路由器设置为使用HTML5历史。但是,要使用此设置我们在角路由器和Grails的UrlMappings申报的路线。

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', {}) 
   }
]);

而UrlMappings.groovy文件:

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 ?

推荐答案

Grails的应用程序提供命名为Spring Bean grailsUrlMappingsHolder ,让在应用程序中定义的URL映射的编程访问(和它的插件)。此Bean的<一个实例href=\"http://grails.org/doc/latest/api/org/$c$chaus/groovy/grails/web/mapping/UrlMappingsHolder.html\"相对=nofollow> UrlMappingsHolder 。你可以阅读从bean的 getUrlMappings URL映射()方法,并从该列表构造你的角度路由器的URL。

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.

这篇关于如何没有Grails的urlMapping中和角路由器之间的重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆