Routing and URL

Hi,
My site structure is destinations/$destination/$article.
I have custom routes, to keep “destinations” for destinations pages, but remove “destinations” for all children.
The URL’s are correct, but when I list all articles, $article->url() returns destinations/$destination/$article.
What’s the best method to take care of routing in $page->url() method ?

Thank you

You can overwrite the URL method in apage model for these pages.

Thanks, it works like a charm.
This is the code I used if it can help someone :

class DestinationPage extends Page
{
	public function url($options = null): string
	{
		if ($parent = $this->parent() && $this->parent()->uid() != 'destinations') {
			return $this->url = $this->parent()->url() . '/' . $this->uid();
		}

		return $this->url = $this->kirby()->url('base') . '/' . $this->uid();
	}

}
1 Like