Coder Social home page Coder Social logo

Comments (4)

JesseRWeigel avatar JesseRWeigel commented on August 14, 2024

I like this idea, but I am not sure how to add it to our current routing setup in server.js.

from franciscan-react.

cr101 avatar cr101 commented on August 14, 2024

This is how I would tackle it over the top of my head.

Take for example pages/job.js, perhaps if possible move the graphql query inside getInitialProps() like below:

static async getInitialProps ({ query: { id, type } }) {
    <Query
          query={JobQuery(type)}
          variables={{ name: id }}
        >
          {result => {
if (result.error)  // Here you either redirect the user to the new post url or to a custom 404 page
/* Either way, have a look at https://github.com/zeit/next.js/wiki/Redirecting-in-%60getInitialProps%60 AND https://stackoverflow.com/questions/45099395/conditional-redirection-in-next-js */
}}
        </Query>

    return { result }
  }

On the backend side - take a look at wp_old_slug_redirect() in https://core.trac.wordpress.org/browser/tags/4.9.7/src//wp-includes/query.php#L0

Btw, last year I opened issue #289 on wp-graphql

Fixing this issue will also fix #93 and #108

I hope this helps at all.

from franciscan-react.

Emiliano-Bucci avatar Emiliano-Bucci commented on August 14, 2024

@cr101 Hi, i was trying to figure out how to handle redirects. You think that redirecting inside the query result is just fine? You know if there's a particular error message that i have to look for?
Thank you very much for your time :)

from franciscan-react.

cr101 avatar cr101 commented on August 14, 2024

@Emiliano-Bucci I haven't implemented this functionality so I'm not sure. If you figure it out please post your solution here

from franciscan-react.

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.