How can I use routing to redirect when a link with the url www.example.com/projects
to the first child of the projects page www.example.com/projects/first-child
?
c::set('routes', array(
array(
'pattern' => 'projects',
'action' => function() {
$firstChild = page('projects')->children()->visible()->first();
if($firstChild) {
go($firstChild->uri());
} else {
return page('projects');
}
}
)
));