Redirect - route cannot be found while reverse-routing. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Redirect - route cannot be found while reverse-routing. (/showthread.php?tid=83054) |
Redirect - route cannot be found while reverse-routing. - groovebird - 09-15-2022 Hi, what does this message mean? in my routes there is a route The call of redirect($route) is not working but the call of $this->response->redirect('/' . $route) is working. What is the correct use of the redirect function? RE: Redirect - route cannot be found while reverse-routing. - kenjis - 09-15-2022 See https://codeigniter4.github.io/CodeIgniter4/general/common_functions.html#redirect RE: Redirect - route cannot be found while reverse-routing. - groovebird - 09-16-2022 (09-15-2022, 07:08 PM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgniter4/general/common_functions.html#redirect in my controller method this is not working: PHP Code: return redirect()->to('/' . $route); RE: Redirect - route cannot be found while reverse-routing. - kenjis - 09-16-2022 Check your real Response headers to see what is different. RE: Redirect - route cannot be found while reverse-routing. - groovebird - 09-16-2022 (09-16-2022, 02:07 AM)kenjis Wrote: Check your real Response headers to see what is different. I can't get it to work. I make a POST-Request to the same page where the form is located and if form validation is successful i want to redirect to another page. By using $this->response->redirect i get a 303 statuscode and in the header there is an entry location with the new page If i use request()->to the location in the header is the same page RE: Redirect - route cannot be found while reverse-routing. - gosocial2 - 09-16-2022 I'd omit '/' in return redirect()->to('/' . $route); Can you just not do return redirect()->to($route) ? RE: Redirect - route cannot be found while reverse-routing. - groovebird - 09-16-2022 (09-16-2022, 08:59 AM)gosocial2 Wrote: I'd omit '/' in return redirect()->to('/' . $route); This is also not working. I don't know what i am doing wrong, but the other call is working with the $this->response... (09-16-2022, 02:07 AM)kenjis Wrote: Check your real Response headers to see what is different. The response header with $this->response->redirect has a location property but with return redirect()->to() the response header has no location property Ok, i think i know what i am doing wrong. I made the redirect call in a function which i call in another function and in every function i have to return the redirect object in order to get it to work. Previously i returned the redirect object only in one function RE: Redirect - route cannot be found while reverse-routing. - kenjis - 09-17-2022 Yes, it is a common mistake. Quote:Important |