Welcome Guest, Not a member yet? Register   Sign In
Redirect - route cannot be found while reverse-routing.
#1

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?
Reply
#2

See https://codeigniter4.github.io/CodeIgnit...l#redirect
Reply
#3

(This post was last modified: 09-16-2022, 01:12 AM by groovebird.)

(09-15-2022, 07:08 PM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgnit...l#redirect

in my controller method this is not working:
PHP Code:
return redirect()->to('/' $route);

// this is working
$this->response->redirect('/' $route); 
Reply
#4

Check your real Response headers to see what is different.
Reply
#5

(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
Reply
#6

I'd omit '/' in return redirect()->to('/' . $route);

Can you just not do return redirect()->to($route) ?

CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5)

Reply
#7

(This post was last modified: 09-16-2022, 12:33 PM by groovebird.)

(09-16-2022, 08:59 AM)gosocial2 Wrote: I'd omit '/' in return redirect()->to('/' . $route);

Can you just not do 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
Reply
#8

Yes, it is a common mistake.

Quote:Important
When you use this function, an instance of RedirectResponse must be returned in the method of the Controller or the Controller Filter. If you forget to return it, no redirection will occur.
https://codeigniter4.github.io/CodeIgnit...l#redirect
Reply




Theme © iAndrew 2016 - Forum software by © MyBB