I am using ReactJS in my project and I would like to access my current URL like by using window.location.href. When I use window.location.href I get an error saying window is not defined.
// --- REACT + CUSTOM-TAGS ---
const SampleApp = ({value}) => {
// --- CUSTOM-SCRIPTS ---
addMeta([
{type: 'meta', content: {content: 'something'}},
{type: 'link', content: {rel: 'http://link'}},
]);
//Append the value from the URL
const prId = "12512" //We can make it dynamic
const url = window.location.href;//window,location.href;
const id = url.substring(url.lastIndexOf('/') + 1);
const output = id.replace(/[a-zA-Z=]/g, '');
return (
<div>
<h1>Hello {value}</h1>
<hr />
<h2>{url} took from prId</h2>
<hr />
<h2><a className="redirect" href={'//www.check.com/prId/' + output} target="_blank">Click Here</a>
</h2>
</div>
);
};