Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

reactjs - getServerSideProps access current browser url

I am calling getServerSideProps and passing in the req and res parameters like this:

export async function getServerSideProps({ req, res }) {}

I need to get the current browser url path and I can't find it in the request object. Is there a way to get the current url inside getServerSideProps?

question from:https://stackoverflow.com/questions/65617150/getserversideprops-access-current-browser-url

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could use resolvedUrl field from the context object.

export async function getServerSideProps({ req, res, resolvedUrl }) {
    // Will log a normalized version of the request URL including query strings  
    console.log(resolvedUrl)

   // Remaining code
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...