-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to force 404? #123
Comments
When a response has a {
name: "NotFound",
path: "(.*)",
// ...
} there is no actual path to generate, just a catch all pattern (does this make sense? it is a bit hard to put into words). If you want to change locations when there is no match (invalid params), you could give the catch all pattern a param name. {
name: "NotFound",
path: ":path(.*)",
// ...
}
{
redirectTo: {
name: "NotFound",
params: { path: "404" }
}
}
// change url to /404 That said, I generally wouldn't recommend redirecting 404s. I would prefer to have that route render its own 404 message for invalid params. Redirecting causes the user to lose context about what location causes the error. For example, if I mistype a URL and get redirected, I have to re-type the whole thing instead of fixing my typo. |
This makes perfect sense.
In terms of this, are you suggesting using the error prop for the response to send a message to page, then rendering my own component for a "404"? |
Yeah, I think that there are a number of approaches that you could take. If you want to have a generic error message for every route that matches but params are invalid, you could return a response() {
if (exists) {
return { body: RouteComponent, ... };
} else {
return { body: NotFound };
} For a route specific 404, I think that setting an response() {
const error = exists ? null : "Thing not found";
return {
body: RouteComponent,
error
};
} And then there is Suspense, which will encourage "distributed" data fetches (whereas using Suspense will be interesting (Curi should be ready to support it the day that it releases) because it removes the need for |
Inside the routes files, I thought I could do
redirectTo: { name: 'NotFound' }
but I get this error:TypeError: Expected "0" to be a string
How do we force redirect to the 404 page if conditions aren't met for a specific route?
The text was updated successfully, but these errors were encountered: