mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-27 18:56:58 +00:00
8f81318ecf
it was a bit cumbersome to navigate by paths accross the app as if one path changes a tiny bit we have to make sure we updated everything everywhere and it's kind of error-prone and cumbersome to build paths by hand. now we have a routes file that describes everything: what is the path to each route, and how to navigate to them. We use a new navigateTo helper that helps us. It could be better typed but i'm a newbie.
22 lines
618 B
TypeScript
22 lines
618 B
TypeScript
import { RouteName } from '@/routes'
|
|
import { navigate } from 'wouter/use-browser-location'
|
|
import { getRouteByName } from './getRouteByName'
|
|
|
|
export const navigateTo = <S = unknown>(
|
|
routeName: RouteName,
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
params?: any,
|
|
options?: { replace?: boolean; state?: S }
|
|
) => {
|
|
const route = getRouteByName(routeName)
|
|
const to = route.to
|
|
? route.to(params)
|
|
: typeof route.path === 'string'
|
|
? route.path
|
|
: null
|
|
if (!to) {
|
|
throw new Error(`Can't find path to navigate to for ${routeName}`)
|
|
}
|
|
return navigate(to, options)
|
|
}
|