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

History usage outside component. Resolve issue #8264 #9439

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@
- xavier-lc
- xcsnowcity
- yuleicul
- Arsikod
30 changes: 30 additions & 0 deletions docs/start/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,36 @@ React Router is built on web standard APIs. [Loaders][loader] and [actions][acti

When you get better at React Router, you get better at the web platform.

## Using history outside React component

Similar to React Router v5 history instance can be used outside of the component.

Main difference is that in v6+ `history` needs to be installed separately.

```jsx
npm install history
```

Then the whole app needs to be wrapped by `unstable_HistoryRouter` imported from `react-router-dom`.

Inside index file:

```tsx
import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
import { createBrowserHistory } from 'history';

export const history = createBrowserHistory();

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
<React.StrictMode>
<HistoryRouter history={history}>
<App />
</HistoryRouter>
</React.StrictMode>
);
```

## Search Params

<docs-info>TODO:</docs-info>
Expand Down