Search code examples
grailsurl-mapping

Grails, different url for same controller and action


I have this urlMappings in grails

"/"(controller: 'home', action: 'index') "/$id"(controller: 'home', action: 'index')

is there a better way to write this, without duplicate code? If I use only one, the other urlMapping won't work.

Thanks in advance


Solution

  • If you want to combine the two URL mappings you can do so by making the id parameter optional like this:

    "/$id?"(controller: 'home', action: 'index')