diff --git a/apps/odyssey-stats/src/page-middleware/setup-context.jsx b/apps/odyssey-stats/src/page-middleware/setup-context.jsx index 7231aee51e5679..cc6f189d02c85d 100644 --- a/apps/odyssey-stats/src/page-middleware/setup-context.jsx +++ b/apps/odyssey-stats/src/page-middleware/setup-context.jsx @@ -9,8 +9,10 @@ export const setupContextMiddleware = ( reduxStore, reactQueryClient ) => { // page.js url parsing is broken so we had to disable it with `decodeURLComponents: false` const parsed = getUrlParts( context.path ); const path = parsed.pathname + parsed.search || null; + context.prevPath = path === context.path ? false : path; context.query = Object.fromEntries( parsed.searchParams.entries() ); + context.pathname = parsed.pathname; context.hashstring = ( parsed.hash && parsed.hash.substring( 1 ) ) || ''; // set `context.hash` (we have to parse manually) diff --git a/client/my-sites/stats/wordads/earnings.jsx b/client/my-sites/stats/wordads/earnings.jsx index 1d01f26ab0ed61..705e39728fd791 100644 --- a/client/my-sites/stats/wordads/earnings.jsx +++ b/client/my-sites/stats/wordads/earnings.jsx @@ -180,16 +180,14 @@ class WordAdsEarnings extends Component {

{ header_text }

diff --git a/client/my-sites/stats/wordads/index.jsx b/client/my-sites/stats/wordads/index.jsx index 86d637aac20986..be17c07bcccd77 100644 --- a/client/my-sites/stats/wordads/index.jsx +++ b/client/my-sites/stats/wordads/index.jsx @@ -4,7 +4,7 @@ import { localize, translate, numberFormat } from 'i18n-calypso'; import { find } from 'lodash'; import moment from 'moment'; import page from 'page'; -import { parse as parseQs, stringify as stringifyQs } from 'qs'; +import { stringify as stringifyQs } from 'qs'; import { Component, Fragment } from 'react'; import { connect } from 'react-redux'; import titlecase from 'to-title-case'; @@ -35,13 +35,6 @@ import HighlightsSection from './highlights-section'; import './style.scss'; import 'calypso/my-sites/earn/ads/style.scss'; -function updateQueryString( query = {} ) { - return { - ...parseQs( window.location.search.substring( 1 ) ), - ...query, - }; -} - const formatCurrency = ( value ) => { return '$' + numberFormat( value, 2 ); }; @@ -116,8 +109,9 @@ class WordAds extends Component { barClick = ( bar ) => { this.props.recordGoogleEvent( 'WordAds Stats', 'Clicked Chart Bar' ); - const updatedQs = stringifyQs( updateQueryString( { startDate: bar.data.period } ) ); - page.redirect( `${ window.location.pathname }?${ updatedQs }` ); + const updatedQs = stringifyQs( { ...this.props.context.query, startDate: bar.data.period } ); + + page.redirect( `${ this.props.context.pathname }?${ updatedQs }` ); }; onChangeLegend = ( activeLegend ) => this.setState( { activeLegend } ); @@ -126,8 +120,8 @@ class WordAds extends Component { if ( ! tab.loading && tab.attr !== this.state.chartTab ) { this.props.recordGoogleEvent( 'WordAds Stats', 'Clicked ' + titlecase( tab.attr ) + ' Tab' ); // switch the tab by navigating to route with updated query string - const updatedQs = stringifyQs( updateQueryString( { tab: tab.attr } ) ); - page.show( `${ window.location.pathname }?${ updatedQs }` ); + const updatedQs = stringifyQs( { ...this.props.context.query, tab: tab.attr } ); + page.show( `${ this.props.context.pathname }?${ updatedQs }` ); } };