`asPath` is omitted in getServerSideProps' parameters and `req.url` is inconsistent regarding query parameters
See original GitHub issueThe new function getServerSideProps does not have the parameter asPath that getInitialProps has.
I tried using req.url instead, but the query parameters are not consistent.
They are not sent during CSR calls, while they are present during SSR calls.
I would prefer to have the whole URL (like asPath) to analyze the URL using a separate module.
Or have the querystring parameters in req.url
How to reproduce
import React from 'react';
import Router from 'next/router';
import { NextPage, GetServerSideProps } from "next";
const changeUrl = () => Router.push('/test?a=2');
const Test: NextPage = (): JSX.Element => {
return (<>
<a onClick={changeUrl}>Click me</a>
</>);
}
export const getServerSideProps: GetServerSideProps = async ({ req, query, params }) => {
console.log('req.url', req.url)
console.log('query', JSON.stringify(query))
console.log('params', JSON.stringify(params))
return { props: {} };
}
export default Test;
When accessing http://localhost:3002/test, we get the following output:
req.url /test
query {}
params undefined
When clicking the link, we get the following output:
req.url /test
query {"a":"2"}
params undefined
When accessing http://localhost:3002/test?a=2 with SSR, we get the following output:
req.url /test?a=2
query {"a":"2"}
params undefined
System information
- Version of Next.js: 9.3.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:16 (4 by maintainers)
Top Results From Across the Web
Data Fetching: getServerSideProps - Next.js
Learn how to fetch data on each request with Next.js. ... The context parameter is an object containing the following keys: params :...
Read more >How to get previous URL in Next.js? - Stack Overflow
I thought the values this.props.router.asPath and nextProps.router.asPath are different. Actually, I want to call router.push after ...
Read more >Handling POST requests in Next.js getServerSideProps
urlencoded() returns an middleware function that has the common 3 arguments, request , response and next . We use promisify to turn the...
Read more >Refreshing Server-Side Props - Next.js - Josh W Comeau
In a Next.js application I'm working on, I have an "admin" page, which lets me manage registered users: A screenshot of a dashboard...
Read more >Package Diff: @netlify/plugin-nextjs @ 3.4.2 .. 3.6.2
feat: merge `next-on-netlify` into `@netlify/plugin-nextjs` ... \"The provided `href` (\".concat(url, \") value is missing query values ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@jgpacker a new feature request for adding a massaged
asPathparam togetServerSidePropsdoes sound like it would be good to open since it’s separate from the initial described issue 👍Closed somewhy. I can give you one more reason to add asPath to request object. It’s
rewritesrules. I can’t get an alias at all ingetServerSideProps