Skip to content

Commit 4cc24e4

Browse files
authored
Update readme.md
1 parent f8f3fa7 commit 4cc24e4

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

readme.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -359,23 +359,22 @@ Router.onAppUpdated = (nextUrl) => {
359359
</ul>
360360
</details></p>
361361

362-
With shallow routing you could chnage the URL without running `getInitialProps` of the page. You'll receive the updated "pathname" and the "query" via the `url` prop of the page.
362+
Shallow routig allows you to change the URL without running `getInitialProps`. You'll receive the updated `pathname` and the `query` via the `url` prop of the same page that's loaded, without losing state.
363363

364364
You can do this by invoking the eith `Router.push` or `Router.replace` with `shallow: true` option. Here's an example:
365365

366-
```js
366+
```jsx
367367
// Current URL is "/"
368368
const href = '/?counter=10'
369369
const as = href
370370
Router.push(href, as, { shallow: true })
371371
```
372372

373-
Now, the URL is updated to "/?counter=10" and page is re-rendered.
374-
You can see the updated URL with `this.props.url` inside the Component.
373+
Now, the URL is updated to `/?counter=10`. You can see the updated URL with `this.props.url` inside the `Component`.
375374

376-
You can also watch for URL changes via [`componentWillReceiveProps`](https://facebook.github.io/react/docs/react-component.html#componentwillreceiveprops) hook as shown below:
375+
You can watch for URL changes via [`componentWillReceiveProps`](https://facebook.github.io/react/docs/react-component.html#componentwillreceiveprops) hook as shown below:
377376

378-
```
377+
```jsx
379378
componentWillReceiveProps(nextProps) {
380379
const { pathname, query } = nextProps.url
381380
// fetch data based on the new query
@@ -384,15 +383,11 @@ componentWillReceiveProps(nextProps) {
384383

385384
> NOTES:
386385
>
387-
> Shallow routing works **only** for same page URL changes.
388-
>
389-
> For an example, let's assume we've another page called "about".
390-
> Now you are changing a URL like this:
386+
> Shallow routing works **only** for same page URL changes. For an example, let's assume we've another page called `about`, and you run this:
391387
> ```js
392388
> Router.push('/about?counter=10', '/about?counter=10', { shallow: true })
393389
> ```
394-
> Since that's a new page, it'll run "getInitialProps" of the "about" page even we asked to do shallow routing.
395-
390+
> Since that's a new page, it'll unload the current page, load the new one and call `getInitialProps` even we asked to do shallow routing.
396391
397392
### Prefetching Pages
398393

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy