## 6.4.9 Named URL Mappings

URL Mappings also support named mappings. Simply put, named mappings are mappings which have a name associated with them. The name may be used to refer to a specific mapping when links are being generated.

The syntax for defining a named mapping is as follows:

    static mappings = {
       name <mapping name>: <url pattern> {
          // …
       }
    }

An example:

    static mappings = {
        name personList: "/showPeople" {
            controller = 'person'
            action = 'list'
        }
        name accountDetails: "/details/$acctNumber" {
            controller = 'product'
            action = 'accountDetails'
        }
    }

The mapping may be referenced in a link tag in a GSP.

    <g:link mapping="personList">List People</g:link>

That would result in:

    <a href="/showPeople">List People</a>

Parameters may be specified using the params attribute.

    <g:link mapping="accountDetails" params="[acctNumber:'8675309']">Show Account</g:link>

That would result in:

    <a href="/details/8675309">Show Account</a>

Alternatively you may reference a named mapping using the link namespace.

    <link:personList>List People</link:personList>

That would result in:

    <a href="/showPeople">List People</a>

The link namespace approach allows parameters to be specified as attributes.

    <link:accountDetails acctNumber="8675309">Show Account</link:accountDetails>

That would result in:

    <a href="/details/8675309">Show Account</a>