Ich verwende ReactJS in meinem Projekt und möchte auf meine aktuelle URL zugreifen, indem ich window.location.href verwende. Wenn ich window.location.href verwende, bekomme ich eine Fehlermeldung, dass das Fenster nicht definiert ist.Fenster ist nicht definiert
// --- 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>
);
};
Überprüfen Sie diese http:// Stackoverflow.com/questions/35374257/error-window-not-defined-in-node-js scheint wie ein ähnliches Problem – Shota