Comments (3)
When a response has a redirectTo
property, it will attempt to generate a pathname
from the matching route. Given a NotFound
route like this:
{
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.
from curi.
This makes perfect sense.
I would prefer to have that route render its own 404 message for invalid params.
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"?
from curi.
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 404
component for the body
.
response() {
if (exists) {
return { body: RouteComponent, ... };
} else {
return { body: NotFound };
}
For a route specific 404, I think that setting an error
message would make sense (and if you have SSR, you could set the status
too) or you could have a route specific error component.
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 route.resolve
may be considered "hoisted"). You might not know if the params are valid until you are rendering and the cache "misses", so you would have to render a not found message from within the component.
Suspense will be interesting (Curi should be ready to support it the day that it releases) because it removes the need for route.resolve
(although I believe that will still be useful).
from curi.
Related Issues (20)
- [React] CSS not loading when using redirectTo HOT 35
- React Packages v2 Plans HOT 2
- Parent Resolve Correlation to Child Route HOT 3
- You should be on Awesome x: HOT 1
- Offscreen positioning possibly bad for RTL languages HOT 2
- 'process' is not defined HOT 6
- SyntaxError: Unexpected token < HOT 5
- .html > .svelte HOT 1
- useRouter not updating state without useResponse HOT 2
- Navigation not working if using svelte beyond v3.6.4 HOT 6
- Pass server side response to client side router on creation HOT 3
- It appears that when I change the url the entire app is re-rendered HOT 1
- Customizing styles of `useNavigationFocus` / ref HOT 2
- How do I change route programmatically HOT 2
- [Feature] Redirect to url HOT 4
- Typescript Type Error for <Link> HOT 3
- Apollo Integration - Prefetching HOT 4
- webiste on different folder structure HOT 5
- @curi/static and svelte HOT 6
- Undefined value for optional route parameter HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from curi.