I am building a basic react app in which clicking a button should open a new page in the same tab. I have used React Router for this but that is not working for me.
I want to redirect to a state say, localhost/test , this is my index.js
import Test from './test/Test'
import { Route } from 'react-router-dom';
const myFirstElement = <>
<Button onClick={() => window.location.href='test'}>Click me</Button>
<Route path='test' element={< Test />}></Route>
</>
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(myFirstElement);
My Test.js contains
const Test = <><h1>Hello React!</h1></>
export default Test;
The problem is above code does not render anything on the screen and it doesn't show any error too. But when I remove the
<Route exact path='/test' element={< Test />}></Route>
above code, a button is rendered on the screen, clicking on the button changes the url but doesn't changes state.
Any help will be appreciated.