Routing Problem: Removing parent in nested slug on a multilingual site

Hello :waving_hand:

I have a problem with rerouting on a multilanguage page:

I have this url:

https://nameofwebsite.de/de/studies/studies/nameofcourse/overview

and want it to be like this:

https://nameofwebsite.de/de/studies/nameofcourse/overview

so get rid of the double studies/studies and reduce it to studies/

I checked the docs and found out how to remove the parent slug.

But somehow I can not get it to work:

        [
            'pattern' => '(:any)/studies/(:all)', 
            'language' => '*',            
            'action'  => function($lang, $uid) { 

                $page = page($uid); 

                if (!$page) {                
                    $page = page('studies/' . $uid);            
                }    

                if (!$page) { 
                    $page = site()->errorPage();
                }

                return site()->visit($page);
            }
        ],
        [
            'pattern' => 'studies/(:all)',
            'language' => '*',
            'action'  => function($uid) {
                go($uid);
            }
        ]

Am I missing something?

Thank you already

Yes, this is not correct, a solution that would work if the overview page does not have children, is the following:

	    [
		    'pattern' => 'studies/(:any)',
		    'language' => '*',
		    'action'  => function($lang, $uid) {
			    $page = page($uid);

			    if (!$page) {
				    $page = page('studies/studies/' . $uid);
			    }

			    if (!$page) {
				    $page = site()->errorPage();
			    }

			    return site()->visit($page, $lang->code());
		    }
	    ],
	    [
		    'pattern' => 'studies/studies/(:any)',
		    'language' => '*',
		    'action'  => function($lang, $uid) {
			    go($lang->code() . '/studies/' . $uid);
			}
	    ],

However, why do you have this duplicate with the same name in the first place, is the studies subpage of studies really needed?

I fixed it, as suggested, by changing the page structure.
I was just curious if it was possible somehow … :upside_down_face:

Thank you!