I have a routing like this:
<BrowserRouter>
<PageRouting >
<Route exact component={DashboardPage} path={routes.ROUTE_MAIN} />
<Route component={DocumentsPage} path={routes.ROUTE_DOCUMENTS} />
<Route component={SettingsPage} path={routes.ROUTE_SETTINGS} />
</PageRouting>
<Redirect to={routes.ROUTE_MAIN} />
</BrowserRouter>
Routes are literal types:
const routes = {
ROUTE_MAIN: '/',
ROUTE_DASHBOARD: '/',
ROUTE_DOCUMENTS: '/documents',
ROUTE_SETTINGS: '/settings',
}
I want my location with type:
type routesKeys = keyof typeof routes
type LocationTypes {
pathname: routesKeys
}
const location = useLocation<LocationTypes>()
But 'location.pathname' is a type of string, not 'routesKeys'.
How can I set type for location.pathname?
EDIT:
'location.pathname' should be a type of:
type routesPaths = typeof routes[routesKeys]