Skip to content

Commit a7a014f

Browse files
committed
fix: route with page functionality
Signed-off-by: otengkwame <[email protected]>
1 parent 8ae5602 commit a7a014f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

CodeIgniter/Framework/core/Router.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,21 @@ protected function _set_default_controller()
294294

295295
$class ??= '';
296296

297+
// Trim '/index' from the end if present
298+
$defaultController = preg_replace('#/index$#', '', $this->default_controller);
299+
300+
// Check if default controller is not 'app' or 'app/index'
301+
// AND if the route value contains 'prefix-route'
302+
if (
303+
$this->default_controller !== 'app'
304+
&& $this->default_controller !== 'app/index'
305+
&& str_contains($this->routes[$defaultController], 'prefix-route')
306+
) {
307+
$baseUrl = $this->config->config['base_url'];
308+
// Redirect to the set default_controller with the base_url
309+
header('Location: ' . $baseUrl . $this->default_controller);
310+
}
311+
297312
if (! file_exists(COREPATH . 'controllers/' . $this->directory . ucfirst($class) . '.php')) {
298313
// This will trigger 404 later
299314
return;

Core/config/routes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
defined('COREPATH') or exit('No direct script access allowed');
33

44
use Base\Route\Route;
5+
use Base\Route\HelperRoute;
6+
57
/*
68
| -------------------------------------------------------------------------
79
| URI ROUTING
@@ -74,6 +76,10 @@
7476
$GLOBALS['default_routes'] = $default;
7577
$GLOBALS['available_routes'] = $route;
7678

79+
// Initialize HelperRoute - this checks for matches
80+
HelperRoute::init();
81+
$route = array_merge($route ?? [], HelperRoute::getRoutes());
82+
7783
/**
7884
* Build routes
7985
*/

0 commit comments

Comments
 (0)