createUseRouter(options)
Create a new router module.
Arguments
options: HistoryOptions
- the options:type: 'browser' | 'hash'
- usebrowser
for html5 navigation, or usehash
to keep routing after#
in the url. Defaultbrowser
.
Returns
{Function}
- a React hook used to mount the module.
Example
// router.ts
import { createUseRouter } from 'typeless-router';
const useRouter = createUseRouter();
// App.tsx
import { useRouter } from './router';
export function App() {
// recommended to mount the module in the main component
useRouter();
return <div>...</div>
}