()
| 104 | } |
| 105 | |
| 106 | componentDidMount() { |
| 107 | this.scrollToHash() |
| 108 | |
| 109 | // We need to replace the router state if: |
| 110 | // - the page was (auto) exported and has a query string or search (hash) |
| 111 | // - it was auto exported and is a dynamic route (to provide params) |
| 112 | // - if it is a client-side skeleton (fallback render) |
| 113 | // - if middleware matches the current page (may have rewrite params) |
| 114 | // - if rewrites in next.config.js match (may have rewrite params) |
| 115 | if ( |
| 116 | router.isSsr && |
| 117 | (initialData.isFallback || |
| 118 | (initialData.nextExport && |
| 119 | (isDynamicRoute(router.pathname) || |
| 120 | location.search || |
| 121 | process.env.__NEXT_HAS_REWRITES || |
| 122 | initialMatchesMiddleware)) || |
| 123 | (initialData.props && |
| 124 | initialData.props.__N_SSG && |
| 125 | (location.search || |
| 126 | process.env.__NEXT_HAS_REWRITES || |
| 127 | initialMatchesMiddleware))) |
| 128 | ) { |
| 129 | // update query on mount for exported pages |
| 130 | router |
| 131 | .replace( |
| 132 | router.pathname + |
| 133 | '?' + |
| 134 | String( |
| 135 | assign( |
| 136 | urlQueryToSearchParams(router.query), |
| 137 | new URLSearchParams(location.search) |
| 138 | ) |
| 139 | ), |
| 140 | asPath, |
| 141 | { |
| 142 | // @ts-ignore |
| 143 | // WARNING: `_h` is an internal option for handing Next.js |
| 144 | // client-side hydration. Your app should _never_ use this property. |
| 145 | // It may change at any time without notice. |
| 146 | _h: 1, |
| 147 | // Fallback pages must trigger the data fetch, so the transition is |
| 148 | // not shallow. |
| 149 | // Other pages (strictly updating query) happens shallowly, as data |
| 150 | // requirements would already be present. |
| 151 | shallow: !initialData.isFallback && !initialMatchesMiddleware, |
| 152 | } |
| 153 | ) |
| 154 | .catch((err) => { |
| 155 | if (!err.cancelled) throw err |
| 156 | }) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | componentDidUpdate() { |
| 161 | this.scrollToHash() |
no test coverage detected