T
TanStack4y ago
optimistic-gold

Type definitions only showing root path

Type definitions for router.navigate only show '/' as valid option. Meanwhile the code for router creation is:
const ROUTES = {
PROJECTS: '/projects',
PROCESSING: '/processing/:key',
PROFILE: '/profile/*',
RESOURCES: '/resources',
}

const routeConfig = createRouteConfig().createChildren((createRoute) => [
createRoute({
path: '/',
component: Project,
}),
createRoute({
path: ROUTES.PROJECTS,
component: Project,
}),
createRoute({
path: ROUTES.PROCESSING,
component: Processing,
}),
createRoute({
path: ROUTES.PROFILE,
component: Profile,
}),
createRoute({
path: ROUTES.RESOURCES,
component: Resources,
}),
])

const router = createReactRouter({ routeConfig })
const ROUTES = {
PROJECTS: '/projects',
PROCESSING: '/processing/:key',
PROFILE: '/profile/*',
RESOURCES: '/resources',
}

const routeConfig = createRouteConfig().createChildren((createRoute) => [
createRoute({
path: '/',
component: Project,
}),
createRoute({
path: ROUTES.PROJECTS,
component: Project,
}),
createRoute({
path: ROUTES.PROCESSING,
component: Processing,
}),
createRoute({
path: ROUTES.PROFILE,
component: Profile,
}),
createRoute({
path: ROUTES.RESOURCES,
component: Resources,
}),
])

const router = createReactRouter({ routeConfig })
2 Replies
compatible-crimson
compatible-crimson4y ago
Hello, we can help ts with 'as const'
const ROUTES = {
PROJECTS: '/projects',
PROCESSING: '/processing/:key',
PROFILE: '/profile/*',
RESOURCES: '/resources',
} as const
const ROUTES = {
PROJECTS: '/projects',
PROCESSING: '/processing/:key',
PROFILE: '/profile/*',
RESOURCES: '/resources',
} as const
Without 'as const' for ts it's just strings https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgIilQ3wG4BYAKCrQgDsBneBAeQFUAVAUQGU4BeOAG8qcMXAAKrAFJcAwhx4AuOAHIA9GBwArJBgaqANKPFSWc3jwCSAOQDiKjVohokDBsDoBzdUoDWSACeRiZiZgBiVgAyXI6aOJjAADZI6gBUIZTiiLzsCBbKaupEDBAArlCuBsaUAL5UVDCBYEhwMG7wgk0tEJiI7Nw8DVk09Ez9nLwA+gCCPFNyLDY8HALCoZIy8opxzrr6mdlmBdb2uzhVHt6+AcE1R6yRMee9yakZ9+IIuWz5vHElcqVNyZWpwFAMOC0RgwYbqdRwAAWEAAbkgoHAQEhGs1Wu0mAAmNbdJC9CaDWbzRbLDhUIA
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
optimistic-gold
optimistic-goldOP4y ago
It's still same I'm doing
const router = useRouter()
router.navigate({ to: '/resources' })
const router = useRouter()
router.navigate({ to: '/resources' })
Here it's giving out error I got the issue, thanks!

Did you find this page helpful?