Learn how to use CoreUI for React.js components in a project built with TanStack Router.
On this page
This guide walks you through adding CoreUI for React.js to a React application built with TanStack Router.
Create a project
Scaffold a new TanStack Router application with the official command and answer the prompts. It sets up a Vite project with file-based routing.
npx create-tsrouter-app@latest my-app
cd my-appInstall CoreUI
Install the React components together with the CSS library that styles them.
npm install @coreui/react @coreui/coreuinpm install @coreui/react-pro @coreui/coreui-proImport styles
Update src/routes/__root.tsx so the stylesheet loads for every route.
import { Outlet, createRootRoute } from '@tanstack/react-router'
import '@coreui/coreui/dist/css/coreui.min.css'
export const Route = createRootRoute({
component: () => <Outlet />,
})import { Outlet, createRootRoute } from '@tanstack/react-router'
import '@coreui/coreui-pro/dist/css/coreui.min.css'
export const Route = createRootRoute({
component: () => <Outlet />,
})Use components
Render your first CoreUI component in a route, for example the index route in src/routes/index.tsx.
import { createFileRoute } from '@tanstack/react-router'
import { CButton } from '@coreui/react'
export const Route = createFileRoute('/')({
component: Index,
})
function Index() {
return <CButton theme="primary">Primary button</CButton>
}import { createFileRoute } from '@tanstack/react-router'
import { CButton } from '@coreui/react-pro'
export const Route = createFileRoute('/')({
component: Index,
})
function Index() {
return <CButton theme="primary">Primary button</CButton>
}Start the development server and open the URL it prints to see the button rendered with CoreUI’s styles.
npm run dev