Redirect page with checkbox in blueprint template

I would like to have in my blueprint a checkbox with label “Redirect the page”.
That means that if it is checked, automatically the page is redirected to the first page of the submenu.

Off course there must be a fallback if there’s no submenu…

Can someone help me?

Something like this, assuming you want to use it in your nav link:

<a href="<php 
if($page->checkboxfield()->bool() && $page->hasChildren()) { 
  echo $page->children()->first()->url(); 
} else {
  echo $page->url();
} ?>">...</a>