0

I have a Rest Api from which I have to retrieve the value which is after clusters in links->href which is '00000000000000000000000000000000'. so how to get that particular value?

[{
"analysisUnits": [
  {
    "links": [
      {
        "href": "http://127.0.0.1/api/v1/clusters/00000000000000000000000000000000/aus/e6ec00e6da1c46c2a1060b3b8ae54765",
        "rel": "self"
      }
    ],
    "name": "OZL6106W",
    "uuid": "e6ec00e6da1c46c2a1060b3b8ae54765"
  }
],
"links": [
  {
    "href": "http://127.0.0.1/api/v1/clusters/00000000000000000000000000000000",
    "rel": "self"
  }
],
"name": "MTS Recording Cluster",
"recordingUnits": [],
"uuid": "00000000000000000000000000000000"}]
7
  • 1
    const link = data[0].links[0].href.split('/'); console.log(link[link.length - 1]) Commented Dec 15, 2021 at 6:11
  • what is data[0] out here? Commented Dec 15, 2021 at 6:29
  • assign JSON to data variable Commented Dec 15, 2021 at 6:31
  • will post it in answer Commented Dec 15, 2021 at 6:31
  • Yes, sure I have small issue. Commented Dec 15, 2021 at 9:46

1 Answer 1

0

useParams .

useParams returns an object of value pairs of URL parameters.

import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
useParams,
} from "react-router-dom";

function BlogPost() {
let { id } = useParams();
return <div style={{ fontSize: "50px" }}>
        Now showing post {id}
        </div>;
}

function Home() {
return <h3>home page </h3>;
}

function App() {
return (
    <Router>
    <Switch>
        <Route path="/page/:id">
        <BlogPost />
        </Route>
        <Route path="/">
        <Home />
        </Route>
    </Switch>
    </Router>
);
}

export default App;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.