An open API service indexing awesome lists of open source software.

https://github.com/alexseitsinger/react-nested-routes

Allows routes that are nested and routes for modals.
https://github.com/alexseitsinger/react-nested-routes

modal react react-router route

Last synced: about 2 months ago
JSON representation

Allows routes that are nested and routes for modals.

Awesome Lists containing this project

README

          

### Table of Contents

- [createRouteComponent][1]
- [Parameters][2]
- [Examples][3]

## 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][4]** An object of route configurations.
- `config.Switch`
- `config.Route`
- `config.config`

### Examples

```javascript
import React from "react"
import { Router, Route, Switch } from "react-router"
import { createRouteComponent } from "@alexseitsinger/react-nested-routes"

import LandingPage from "./pages/landing"
import AboutPage from "./pages/about"
import AboutModalPage from "./pages/about-modal"
import NotFoundPage from "./pages/not-found"

const config = {
path: "/",
Component: LandingPage,
routes: [
{path: "*", Component: NotFoundPage},
{path: "about", Component: AboutPage, routes: [
{path: "modal", Component: AboutModalPage, modal: true},
]}
]
}

function App(props) {
const RouteComponent = createRouteComponent({ Switch, Route, config })
return (





)
}

export default App
```

Returns **[Function][5]** A stateless functional component to be used in the root route.

[1]: #createroutecomponent

[2]: #parameters

[3]: #examples

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function