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

Categories

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

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

1 Answer

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...