みなさん、grails での URL マッピングについて質問があります。ページ名と ID を使用して、seo フレンドリーな URL を作成しようとしています。URLMapping で次のようになりました。
class UrlMappings {
static mappings = {
"/$id/$name"{
controller = "page"
action = "view"
}
"500"(view:'/error')
"/"(controller:"index")
}
}
Witch は動作していますが.... URL バーの ID がクリアされないため、最初にリンクをクリックしたときはすべてうまくいきます: http://localhost:8080/SuurdGasControl/2/Gasmetingen
しかし、次のページが表示されます: http://localhost:8080/SuurdGasControl/2/6/Ontgassen
ID「2」は削除されていないことに注意してください...
助けや考えはありますか?
アップデート
URLMapping は次のようになります。
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")
}
}
リンクの作成は次のように簡単です。
<g:link mapping="stfu" params="[id: pageId, name: pageName]">${oNavigationInstance.toString()}</g:link>