Giter VIP home page Giter VIP logo

Comments (4)

pshrmn avatar pshrmn commented on May 27, 2024

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.

  1. 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

  1. 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.

stalniy avatar stalniy commented on May 27, 2024

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.

pshrmn avatar pshrmn commented on May 27, 2024

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.

stalniy avatar stalniy commented on May 27, 2024

Awesome! Much appreciated!

from curi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.