Basic Routing

Basic Routing

Basic Routing

Basic Routing

Basic Routing

This code defines two routes: the home route and the user route. The home route is located at the root path (/) and the user route is located at the /users/:name path. The :name parameter will be passed to the UserComponent component as a prop.To use the routes, you can use the router.navigate() method. For example, the following code will navigate to the user page for the user with the name "John Doe":


const homeRoute = {
  path: '/',
  component: HomeComponent,
};

const userRoute = {
  path: '/users/:name',
  component: UserComponent,
};

class App extends Component {
  render() {
    return (
      <Routes>
        <Route path="/" component={HomeComponent} />
        <Route path="users/:name" component={UserComponent} />
      </Routes>
    );
  }
}

export default App;


This code defines two routes: the home route and the user route. The home route is located at the root path (/) and the user route is located at the /users/:name path. The :name parameter will be passed to the UserComponent component as a prop.

To use the routes, you can use the router.navigate() method. For example, the following code will navigate to the user page for the user with the name "John Doe":


const router = new Router();
router.navigate('/users/John Doe');


This code will navigate to the /users/John Doe path, which will render the UserComponent component with the name prop set to "John Doe".