Router

The default export from react-sprout is a function that creates a Router component from a set of routes.

import Routes from 'react-sprout';

import Home from './home.jsx';
import Todos from './todos.jsx';

let Router = Routes(
	<>
		<Home path="home" />
		<Todos path="todos" />
	</>,
);

The result is a Router component that can be used anywhere in your application.

function Application() {
	return <Router />;
}

The Router will render the element of which the path property corresponds to the current url.

In this case:

  • the url /home will make the router render <Home />
  • the url /todos will make the router render <Todos />