Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/acrool/acrool-react-router-hash

Hash Route + History Route Additional based for React Route v6
https://github.com/acrool/acrool-react-router-hash

hash-router react-router

Last synced: 2 months ago
JSON representation

Hash Route + History Route Additional based for React Route v6

Awesome Lists containing this project

README

        

# Acrool React Router Hash


Acrool React Router Hash Logo


Hash Route + History Route Additional based for React Route v6

[![NPM](https://img.shields.io/npm/v/@acrool/react-router-hash.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-router-hash)
[![npm](https://img.shields.io/bundlejs/size/@acrool/react-router-hash?style=for-the-badge)](https://github.com/acrool/@acrool/react-router-hash/blob/main/LICENSE)
[![npm](https://img.shields.io/npm/l/@acrool/react-router-hash?style=for-the-badge)](https://github.com/acrool/react-router-hash/blob/main/LICENSE)

[![npm downloads](https://img.shields.io/npm/dm/@acrool/react-router-hash.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-router-hash)
[![npm](https://img.shields.io/npm/dt/@acrool/react-router-hash.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-router-hash)

> with react-router-dom version 6.x

## Features

- With react-router-dom version 6.x
- In CSR, it is easy to implement the light box routing function
- Modified and enhanced HashRouter function by react-router-dom, supports path params
- Extract the shared optical box to the router to separate dependencies
- With [@acrool/react-modal](https://github.com/acrool/acrool-react-modal) to support persistent lightbox

## Install

```bash
yarn add @acrool/react-router-hash
```

## Usage

```tsx
import {Route, Routes, useLocation} from 'react-router-dom';
import {HashRoutes, HashRoute} from '@acrool/react-router-hash';
import {unstable_HistoryRouter as Router} from "react-router-dom";

const history = createBrowserHistory({window});

const MainRouter = () => {
return

{/* Base pathname */}

} />
}/>

{/* Hash pathname*/}

}/>

}>
}/>
}/>


};

import {useHashParams} from '@acrool/react-router-hash';

const Dashboard = () => {
const navigate = useNavigate();

return


Dashboard


This page dashboard.


navigate({hash: '/control/editAccount/1'})}>EditAccount HashModal
navigate({hash: '/control/editPassword'})}>EditPassword HashModal
;
};

const EditAccount = () => {
const {id} = useHashParams<{id: string}>();
const navigate = useNavigate();
const pathname = useHashPathname();

return <>

hash pathname: {pathname}


useHashParams id: {id}


navigate({hash: undefined})}>Close HashModal
>;
};
```

There is also a example that you can play with it:

[![Play react-editext-example](https://raw.githubusercontent.com/acrool/acrool-react-router-hash/main/play-in-example-button.svg)](https://acrool-react-router-hash.pages.dev)

## License

MIT © [Acrool](https://github.com/acrool) & [Imagine](https://github.com/imagine10255)