install rout e
npm install react-router-dom
npm install react-router-dom@latest
components
about.js
// About.js
import React from 'react';
const About = () => {
return (
<div>
<h1>About Us</h1>
<p>About page content goes here.</p>
</div>
);
};
export default About;
home.js
// Home.js
import React from 'react';
const Home = () => {
return (
<div>
<h1>Welcome to the Home Page</h1>
<p>This is the home page content.</p>
</div>
);
};
export default Home;
routes.js
// src/routes.js
import React from 'react';
import { Routes, Route } from 'react-router-dom'; // Updated import
import Home from './components/Home';
import About from './components/About';
const AppRoutes = () => {
return (
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
);
};
export default AppRoutes;
app.js
// src/App.js
import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import Routes from './routes';
const App = () => {
return (
<Router>
<div>
<h1>My React App</h1>
<Routes />
</div>
</Router>
);
};
export default App;
app.js
// src/App.js
import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import Routes from './routes';
const App = () => {
return (
<Router>
<div>
<h1>My React App</h1>
<Routes />
</div>
</Router>
);
};
export default App;
=
No comments:
Post a Comment