Route based on toggle value

I am trying to create a maintanance mode for the editors to easily adapt. In the future I will adjust to only route if the user is not logged in so editors would still see the page. But currently I am testing the route only based on the toggle inside my panel.

While this works inside a template:

<?= $site->maintanance()->toBool() ? 'Maintenance mode' : 'Page running normally' ?>

This does not inside config.php:

'routes' => [
        [
            'pattern' => '(:all)',
            'action'  => function ($path) {
                $site = site();
                
                if ($site->maintanance()->toBool()) {
                    if ($path === 'maintanance') {
                        return Page::factory([
                            'slug' => 'maintanance',
                            'template' => 'maintanance',
                            'model' => 'maintanance',
                            'content' => [
                                'title' => 'Maintenance',
                                'uuid'  => Uuid::generate(),
                            ]
                        ]);
                    }

                    return go('/maintanance');
                }
            }
        ]
    ]

I am guessing that I cannot access blueprint fields like this in config.php. Is there another way to do this?

The if statement should work, however, both the redirect and the second if statement that check the $path value are unnecessary, the route should not redirect but show the maintenance page if the toggle is set to true.

Thanks @texnixe for responding so quickly.

That was exactly the solution:

'routes' => [
        [
            'pattern' => '(:all)',
            'action'  => function ($path) {
                $site = site();

                if ($site->maintanance()->toBool()) {
                    return Page::factory([
                        'slug' => 'maintanance',
                        'template' => 'maintanance',
                        'model' => 'maintanance',
                        'content' => [
                            'title' => 'Maintenance',
                            'uuid'  => Uuid::generate(),
                        ]
                    ]);
                }
            }
        ]
    ]

I thought this was the solution. It was for the case when my bool is true. But if maintanance mode i get to the error page.

i tried return false; and return null; after the if statement. both did not work. how would I make the route fully conditional on only doing anything if my toggle is off?

Add $this->next(); outside the if statement, this then triggers the next available route.

Yes that works. Thank you