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

148
Views
How to split url in reactJs

The full url is /login?redirect=shipping. I want to split it into two parts like this - /login?redirect and shipping. I need the second part of the url. that is shipping How can I do this in reactjs??

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use useSearchParams from react-router-dom v6.

You can also use URLSearchParams (Provided by Browsers)

In your case it would be as follows:

import React from "react";
import { useSearchParams, useLocation } from "react-router-dom";

export const App = () => {
    const [searchParams, setSearchParams] = useSearchParams();
    const { search } = useLocation();

    console.log(searchParams.get("redirect"));

    // if it's more than 1 value for redirect i.e. redirect=shipping&redirect=shipped
    console.log(searchParams.getAll("redirect")); // will return array of value

    // you can use URLSearchParams also by passing search query
    console.log(new URLSearchParams(search).get("redirect"));
    // URLSearchParams is provided by Browser.
    return <div>Search Param</div>;
};

PS: Follow useSearchParams approach if using react and specifically react-router-dom V6 or else go for URLSearchParams

about 4 years ago · Santiago Trujillo Report
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!