CodeIgniter4: Bug: Route redirection not working

Describe the bug After using

$routes->addRedirect('example', 'profile/dashboard');

I get an error

key() expects parameter 1 to be array, string given

but if the second param I set as named route then everything is working properly. The problem exists only when the second param is a URI

CodeIgniter 4 version 4.0.2

Affected module(s)

Router/Router.php at line 430

I not sure but here I found some changes for this line https://github.com/codeigniter4/CodeIgniter4/pull/2481/files#diff-d2374d65fd714c18dbee9f5adaa8dd6cL488

Expected behavior, and steps to reproduce if appropriate Redirection working properly for the second param as a URI .

Context

  • OS: Ubuntu
  • PHP version 7.3

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

It’s more complicated 😃 It looks like redirection doesn’t work for addresses with / eg checkout/shoppingCart, profile/orders when route name is defined

Now the redirection works

$routes->addRedirect('asdasd', 'checkout/shoppingCart', 301);

$routes->get('shoppingCart', 'CheckoutController::shoppingCart');

Now the redirection does not work:

$routes->addRedirect('asdasd', 'checkout/shoppingCart', 301);

$routes->get('shoppingCart', 'CheckoutController::shoppingCart', ['as' => 'checkout.shoppingCart']);

This problem is because addRediret before setRoutes, you can run

$routes->get('shoppingCart', 'CheckoutController::shoppingCart');
$routes->addRedirect('asdasd', 'checkout/shoppingCart', 301);

I think this is the correct order

I just use $routes->add to test, This looks bad.

Regarding your second question, I think you are right, I have made a change