Grails urlmapping using id and name

Hi everyone, I have a question about urlmapping in grails. I am trying to make seo friendly url using page name and id. I got the following in my URLMapping:

class UrlMappings { static mappings = { "/$id/$name"{ controller = "page" action = "view" } "500"(view:'/error') "/"(controller:"index") } } 

Witch works, but .... id will not be cleared in urlbar, so when you click the link for the first time everything goes fine: http: // localhost: 8080 / SuurdGasControl / 2 / Gasmetingen

But for the next page, this shows: http: // localhost: 8080 / SuurdGasControl / 2/6 / Ontgassen

note that the identifier "2" has not been deleted ...

Any help or thoughts?

UPDATE

URLMapping now looks like this:

 class UrlMappings { static mappings = { "/$controller/$action?/$id?"{ constraints { // apply constraints here } } name stfu: "/id/$id/$name" { controller = 'page' action = 'view' } "500"(view:'/error') "/"(controller:"index") } } 

Creating a link is as simple as:

 <g:link mapping="stfu" params="[id: pageId, name: pageName]">${oNavigationInstance.toString()}</g:link> 
+4
source share
1 answer

Try using named URL mapping as described at http://docs.grails.org/latest/guide/theWebLayer.html#namedMappings

+3
source

Source: https://habr.com/ru/post/1342097/


All Articles