Comments (4)
Hmm, I would have to think about whether I want that to be part of the official API. When a response has a redirect
property, we end up generating a url
string and using that to navigate, so it wouldn't be the worst thing to have url
be an optional property that we use instead of a requiring the route name/params, etc. I think that I used to have something like that, but then I would have to pass in a way for a user to generate a url
from a route's name
/params
.
In the mean time, there are a couple of possible approaches that you could take.
- Your catch all route could match multiple segments and you could redirect to that route with an array of path segments as the param. This was my initial thought, and may work, but it is pretty hacky.
https://codesandbox.io/s/curi-in-app-url-redirect-ctsfg
- Another option would be to have the catch all route return a response with the URL to redirect to attached to the response's data. Then in your root component, you could detect that data and redirect yourself. This is a bit more hands on, but maybe less hacky.
What sorts of URLs do you need to preserve? If they are all blog posts that have a common format, would you not be able to just have a route that matches the old blog post URL format and redirects?
const routes = prepareRoutes([
{ name: 'Post', path: ':lang/:slug', ... },
{
name: 'Old Post',
path: ':slug',
respond({ match }) {
return {
redirect: { name: 'Post', params: match.params, ... }
};
}
}
},
]);
I haven't been giving Curi much love lately, but I'm hoping to find the time to give it a good evaluation to figure out what is working and what could be improved. I'll certainly keep this in mind when I do that.
from curi.
I can make a PR with optional url
option if you ok with that. Currently I also do something Jacky there :) https://github.com/stalniy/freaksidea-pwa/blob/master/src/config/routes.js#L79
from curi.
I just published @curi/router
v2.1.0, which allows you to use redirect: { url: '/some-place' }
. I haven't written documentation yet (and just realized that I didn't update the changelog), but it's there. If you need search/hash, you have to include them in the url string yourself instead of providing them as separate properties.
respond({ match }) {
const { location } = match.
return {
redirect: {
url: `${DEFAULT_LANG}/${location.pathname}${location.search}${location.hash}`,
}
};
}
Please let me know if there are any issues with it, but I believe that this solves your use case.
from curi.
Awesome! Much appreciated!
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
- 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.