Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist query string when navigating #8683

Merged
merged 3 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Expand Up @@ -13,6 +13,7 @@
- hongji00
- hsbtr
- hyesungoh
- IbraRouisDev
- JakubDrozd
- jmargeta
- jonkoops
Expand Down
5 changes: 4 additions & 1 deletion docs/getting-started/tutorial.md
Expand Up @@ -812,6 +812,7 @@ import { getInvoice, deleteInvoice } from "../data";

export default function Invoice() {
let navigate = useNavigate();
let location = useLocation();
let params = useParams();
let invoice = getInvoice(parseInt(params.invoiceId, 10));

Expand All @@ -826,7 +827,7 @@ export default function Invoice() {
<button
onClick={() => {
deleteInvoice(invoice.number);
navigate("/invoices");
navigate("/invoices" + location.search);
}}
>
Delete
Expand All @@ -837,6 +838,8 @@ export default function Invoice() {
}
```

Notice we used `useLocation` again to persist the query string by adding `location.search` to the navigation link.

## Getting Help

Congrats! You're all done with this tutorial. We hope it helped you get your bearings with React Router.
Expand Down