Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "asPath" (or similar) in getServerSideProps #16407

Closed
jgpacker opened this issue Aug 20, 2020 · 1 comment · Fixed by #17082
Closed

Add "asPath" (or similar) in getServerSideProps #16407

jgpacker opened this issue Aug 20, 2020 · 1 comment · Fixed by #17082
Assignees
Milestone

Comments

@jgpacker
Copy link

jgpacker commented Aug 20, 2020

Feature request

Add in getServerSideProps's function a parameter similar to asPath from getInitialProps, which would contain the URL path the user will see in it's browser.

Use cases include path logging and dynamic path analysis.

Describe the solution you'd like

For a file ./pages/items-search/[[...slug]].js, this parameter would show what the user will see after getServerSideProps returns, such as:

  • /items-search/
  • /items-search/?order=asc
  • /items-search/category-one/
  • /items-search/category-one/sub-category-two/
  • /items-search/category-one/?order=asc
  • /items-search/category-one/sub-category-two/?order=desc&query=super%20item

The parameter does not need to be necessarily named asPath.

Describe alternatives you've considered

It is technically possible to build the desired value by joining the folders+file name with the slug parameters and querystring.
It works, but I didn't find an easy way of dynamically retrieving the current path prefix (i.e. folders+file name, without including slug parameters or querystring).
req.url can help, but it becomes something like /_next/data/BUILD_ID/PAGE_NAME.json?a=b during CSR requests.

@ijjk ijjk self-assigned this Sep 14, 2020
@kodiakhq kodiakhq bot closed this as completed in #17082 Sep 14, 2020
kodiakhq bot pushed a commit that referenced this issue Sep 14, 2020
This continues off of #17081 and provides this normalized `asPath` value in the context provided to `getServerSideProps` to provide the consistent value since the request URL can vary between direct visit and client transition and the alternative requires building the URL each time manually. 

Kept this change separate from #17081 since this is addressing a separate issue and allows discussion separately. 

Closes: #16407
@Timer Timer added this to the iteration 9 milestone Sep 14, 2020
HitoriSensei pushed a commit to HitoriSensei/next.js that referenced this issue Sep 26, 2020
This continues off of vercel#17081 and provides this normalized `asPath` value in the context provided to `getServerSideProps` to provide the consistent value since the request URL can vary between direct visit and client transition and the alternative requires building the URL each time manually. 

Kept this change separate from vercel#17081 since this is addressing a separate issue and allows discussion separately. 

Closes: vercel#16407
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants