• Resolved kamal612

    (@kamal612)


    Hi Marco, thanks for the very useful plugin.

    The problem I am facing is that I am not getting the query param in the react app.

    The app works fine locally and visiting the URL: http://localhost:3000/:postId (Where postId is a dynamic ID value of blogpost I want to see) loads correct blogpost.

    But when I add this in ReactPress inside WordPress, and I open a URL like: https://mydomain.com/reactpressapp/:postId, then it doesn’t catch the value of postId. And actually it gives the value of postId as reactpressapp i.e. postId === reactpressapp.

    Maybe, you can give me a hint why is this happening and how can I fix it?

    Thanks!!!

    • This topic was modified 4 years, 2 months ago by kamal612.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author rockiger

    (@rockiger)

    Assuming that you use React-Router try to go to Settings > Permalink in your WordPress and save the settings there again. This rewrites the permalink cache.

    If this doesn’t help, post the code you are using here.

    Thread Starter kamal612

    (@kamal612)

    @rockiger thanks for the quick response.

    I tried the method you suggested but to no avail.

    My code is as follows:

    app.js

    <Router>
      <Switch>
        <Route
          path="/aggregated-analytics/:surveyId"
          component={AggregatedAnalyticsPage}
        ></Route>
        <Route path="/:id" component={SurveyPage}></Route>
      </Switch>
    </Router>

    And survey.js file which export the component SurveyPage has this code.

    export function SurveyPage() {
      const { id } = useParams();
      const [survey, setSurvey] = useState(null);
    
      useEffect(() => {
        axios.get(<code>${API_URL}/surveys/${id}</code>).then((response) => {
          setSurvey(response.surveyJSON);
        });
      }, []);
    
      var model = new Survey.Model(survey);
    
      return (
        <div className="container">
          <Survey.Survey
            model={model}
          />
        </div>
      );
    }

    PS: To simplify things, I asked about postId in my original question. But actually, my data contains surveys. So, we can replace postId with surveyId.

    Thread Starter kamal612

    (@kamal612)

    Hi @rockiger, any help? thanks.

    Plugin Author rockiger

    (@rockiger)

    Sorry, I am bit short on time right now.

    What is the whole outpout of useParams and useLocation?

    Probably your Rout should be something like this in the live environment:

    <Route path="/reactpressapp/:id" component={SurveyPage}></Route>

    Best
    Marco

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Can’t get query param in the React app’ is closed to new replies.