Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
How to refresh using react router to same location i was before

So I know that the question has allready been asked before. And I actually found the solution for the problem. But that's not exactly the solution I want. I'll explain first my problem. I am using React router and express. When we first visit the site ( A GET to the root path '/'), the 'index.html' file is serverd(with the react code that goes with it). But when i am in sub path, say 'https://example.com/my-sub-path', and then refresh I get 'Cannot GET/my-sub-path'. So I fixed this problem by adding this code:

app.get('*',(inRequest:Request, inResponse:Response)=>{
   inResponse.status(300).redirect('/');
});

Before this one:

    app.get('/',(inRequest:Request, inResponse:Response)=>{
        inResponse.status(200).sendFile(path.join(__dirname,'../../client/dist/'));
    });

Which redirects me to the HOME view (the root path) whenever I refresh.

What I want is this behavior:

I am on path 'https://example.com/my-sub-path' (at this point everything's fine) And then I refersh THIS ROOT and my navigator is refreshed yet I'm still in the same view as earlier (I wouldn't be redirected to the root). Any one can answer me ? I really don't know where to start :)

Oh! For example, I've seen lots of sites that are SPAs, but when you refresh you always have the same page, despite the url. For example google mui site

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!