开发者

Rewriting URL for the default action in controllers

开发者 https://www.devze.com 2023-01-11 13:27 出处:网络
I\'m having trouble rewriting URL\'s in Grails: I\'ve got 2 controllers BlogController开发者_如何学Go and ProjectsController each with a default def index = { } and matching view.

I'm having trouble rewriting URL's in Grails:

I've got 2 controllers BlogController开发者_如何学Go and ProjectsController each with a default def index = { } and matching view.

Now when I create the following links:

<g:link controller="blog">Blog</g:link>
<g:link controller="projects">Projects</g:link>

They get translated to http://localhost:8080/myapp/blog/index and http://localhost:8080/myapp/projects/index. But want them (and all other controllers default action) to be without the trailing /index.

Can anyone help me do this?


Try to specify action parameter in link tag as space.

<g:link controller="projects" action=" ">Projects</g:link>


Try using a Named URL Mapping

Add this to your grails-app/conf/UrlMappings.groovy

    name blog: "/blog" {
            controller = "blog"
            action = "index"
    }
    name projects: "/projects" {
            controller = "projects"
            action = "index"
    }

and change your links to use the mapping parameter:

<g:link mapping="blog">Blog</g:link>
<g:link mapping="projects">Projects</g:link>
0

精彩评论

暂无评论...
验证码 换一张
取 消