I am writing a website in ReactJS and I am using Mantine for styling. When I try to use react router as seen below, the mantine components no longer work.
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import { MantineProvider } from '@mantine/core';
import Home from './pages/Home';
import Explore from './pages/Explore';
import './index.css';
const router = createBrowserRouter([
{
path: '/',
element: <Home />,
},
{
path: '/explore',
element: <Explore />,
}
]);
createRoot(document.getElementById('root')!).render(
<StrictMode>
<MantineProvider>
<RouterProvider router={router} />
</MantineProvider>
</StrictMode>,
);
I read about the MantineProvider but couldn’t find anything about this issue/ how to fix it. It says the provider should be at the root of the website.
This is what its meant to look like.
This is what it looks like when adding the router
2
Answers
The fix was adding this import in main.tsx:
is this your issue – https://github.com/orgs/mantinedev/discussions/6277
also added a solution that should work, check both and let me know if it works!
Make sure that your custom CSS (index.css) doesn’t override Mantine’s styles unless intended. It’s better to import Mantine styles first, then your custom CSS.