Web / TanStack Interview Questions
How do you define routes in TanStack Router with Vue?
Use createRootRoute() for the layout root and createRoute() for each page. Routes are assembled into a typed tree and passed to createRouter().
// routes/__root.ts
import { createRootRoute, RouterOutlet } from "@tanstack/vue-router"
import { h } from "vue"
export const rootRoute = createRootRoute({
component: ()=>h("div",null,[h(RouterOutlet)]),
})
// routes/users/$userId.ts — $ marks a dynamic segment
import { createRoute } from "@tanstack/vue-router"
import UserDetailPage from "../pages/UserDetailPage.vue"
export const userDetailRoute = createRoute({
getParentRoute: ()=>rootRoute,
path: "/users/$userId",
component: UserDetailPage,
})
// Assemble the tree
const routeTree = rootRoute.addChildren([userDetailRoute])
export const router = createRouter({ routeTree })
// Access typed params in a component
import { useParams } from "@tanstack/vue-router"
const { userId } = useParams({ from:"/users/$userId" })
// userId typed as string; TS error on wrong param name
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
