项目作者: alexseitsinger

项目描述 :
Allows routes that are nested and routes for modals.
高级语言: JavaScript
项目地址: git://github.com/alexseitsinger/react-nested-routes.git
创建时间: 2019-04-16T23:37:31Z
项目社区:https://github.com/alexseitsinger/react-nested-routes

开源协议:BSD 2-Clause "Simplified" License

下载


Table of Contents

createRouteComponent

Creates a stateless functional component for use in the root route. Routes that are marked with modal: true are rendered WITH their parent route component.

Parameters

  • config Object An object of route configurations.
    • config.Switch
    • config.Route
    • config.config

Examples

  1. import React from "react"
  2. import { Router, Route, Switch } from "react-router"
  3. import { createRouteComponent } from "@alexseitsinger/react-nested-routes"
  4. import LandingPage from "./pages/landing"
  5. import AboutPage from "./pages/about"
  6. import AboutModalPage from "./pages/about-modal"
  7. import NotFoundPage from "./pages/not-found"
  8. const config = {
  9. path: "/",
  10. Component: LandingPage,
  11. routes: [
  12. {path: "*", Component: NotFoundPage},
  13. {path: "about", Component: AboutPage, routes: [
  14. {path: "modal", Component: AboutModalPage, modal: true},
  15. ]}
  16. ]
  17. }
  18. function App(props) {
  19. const RouteComponent = createRouteComponent({ Switch, Route, config })
  20. return (
  21. <Router>
  22. <Layout>
  23. <Route component={RouteComponent} ></Route>
  24. </Layout>
  25. </Router>
  26. )
  27. }
  28. export default App

Returns Function A stateless functional component to be used in the root route.