private function getRedirectionUrl(
        AdminInterface $admin,
        ActionInterface $action,
        AdminConfiguration $configuration,
        Request $request
    ): string {
        if ('edit' === $action->getName()) {
            $routeName = RoutingLoader::generateRouteName(
                $admin->getName(),
                'list',
                $configuration->get('routing_name_pattern')
            );
            $url = $this->router->generate($routeName);

            return $url;
        }

        // When the create form is submitted, the user should be redirected to the edit action after saving the form
        // data
        if ('create' === $action->getName()) {
            $targetAction = 'list';
            $routeParameters = [];

            if (!$request->get('submit_and_redirect')) {
                $targetAction = 'edit';
                $routeParameters = [
                    'id' => $admin->getEntities()->first()->getId(),
                ];
            }
            $routeName = RoutingLoader::generateRouteName(
                $admin->getName(),
                $targetAction,
                $configuration->get('routing_name_pattern')
            );
            $url = $this->router->generate($routeName, $routeParameters);

            return $url;
        }

        if ('delete' === $action->getName()) {
            $routeName = RoutingLoader::generateRouteName(
                $admin->getName(),
                'list',
                $configuration->get('routing_name_pattern')
            );
            $url = $this->router->generate($routeName);

            return $url;
        }

        throw new Exception('Unable to generate an redirection url for the current action');
    }