I have URL like http://localhost:3000/aaa/bbb/ccc and each time i refresh the /bbb part is changed. How can I get /bbb segment and current value of /bbb as a string inside return() in React Native
const url = new URL("https://localhost:3000/aaa/bbb/ccc");
I try this and didnt work thank you
deniz demiieras is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
You can do it by separating the URI
const url = new URL("https://localhost:3000/aaa/bbb/ccc");
const splitUrl = url.pathname.split("/") // Output: ["", "aaa", "bbb", "ccc"]
const selectB = splitUrl[2] // Output: "bbb"
sorry for bad informations but i made it
const [data, setData] = useState('');
const fetchX = () => {
axios.get('http://localhost:3000/aaa/bbb/ccc')
.then((response) => {
setData(response.data.ITSTHEURL)
});
};
useEffect(() => {
fetchX();
}, []);
return (
<View style={{ paddingTop: 60 }}>
<Text>{data.split("/")[2]}</Text>
deniz demiieras is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.