I am seeking a solution to modify a URL query for the current page in Next JS without causing the page change event to trigger. Specifically, I need to be able to remember the week that is being viewed in a calendar, much like how Google Calendar operates. Here's what I have attempted so far:
import Calendar from '../components/Calendar'
import { formatDate } from '../utils'
class CalendarDashboardPage extends React.Component {
refreshQuery(date) {
const { pathname, asPath } = this.props.router
const d = formatDate(date) // YYYY-MM-DD
this.props.router.push(pathname, asPath, { query: { d }, shallow: true })
}
render() {
return <Calendar onDateChange={this.refreshQuery) />
}
}
export default withRouter(CalendarDashboardPage)
While my approach appears to be functional, using this.props.router.push
triggers a page change in Next JS, which inadvertently displays the loading bar implemented (nprogress). In an attempt to resolve this issue, I experimented with
this.props.router.push({ query: { d } });
, but it did not produce the desired outcome.
Hence, my inquiry lies in finding out if there exists a method to adjust the router query without initiating events like routeChangeStart(url)
?