# react-router-async-component

> Async route component for react-router

Latest version **0.1.2** (published 2017-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-router-async-component
pnpm add react-router-async-component
yarn add react-router-async-component
bun add react-router-async-component
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2017-04-07 |
| First published | 2017-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | linyupark@gmail.com |
| Maintainers | linyupark |
| Keywords | react, async, router, component |

## Links

- npm: https://www.npmjs.com/package/react-router-async-component
- npm.io page: https://npm.io/package/react-router-async-component

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2017-04-07
- 0.1.1 — 2017-04-06
- 0.1.0 — 2017-04-03
- 0.0.9 — 2017-04-03
- 0.0.8 — 2017-04-01
- 0.0.7 — 2017-04-01
- 0.0.6 — 2017-03-31
- 0.0.5 — 2017-03-31
- 0.0.4 — 2017-03-30
- 0.0.3 — 2017-03-30
- 0.0.2 — 2017-03-30
- 0.0.1 — 2017-03-30

## README

# react-router-async-component

Async route component for [React-router](https://github.com/ReactTraining/react-router)

`npm i -D react-router-async-component`

react-router-async-component provides `<Acomponent>` tag to load your components lazily.

## Usage Example
```js
import React from 'react'
import { render } from 'react-dom'
import { HashRouter, Route, Link } from 'react-router-dom'
import Acomponent from 'react-router-async-component'

const Page = (props) => {

  const 
    page = props.match.params.wildcard || 'index'
  return <Acomponent from={
      import(`page/${page}`)
    } notFound={
      import(`page/notfound`)
    } onError={
      /* new */
      import(`page/error`)
    }/>
}

const Main = () => (
  <HashRouter>
    <div>
      <ul>
        <li><Link to="/">Home</Link></li>
        <li><Link to="/clock">Clock</Link></li>
      </ul>
      <hr/>
      <Route exact path="/" component={
        () => <Acomponent from={import('page/home')}/>
      }/>
      <Route path="/clock" component={
        () => <Acomponent from={import('page/clock')} name="AliasName"/>
      }/>
      <Route path="/:wildcard?" component={Page}/>
    </div>
  </HashRouter>
)

render(<Main/>, document.querySelector('#app'));
```

home.jsx
```js
import React, { Component } from 'react'
class Home extends Component {
  render() {
    return (
      <div>Home</div>
    )
  }
}
// props.name === default
export default Home
```

clock.jsx
```js
import React from 'react'
class Clock extends Component {
  render() {
    return (
      <div>Clock</div>
    )
  }
}
// props.name === AliasName
export { Clock as AliasName }
```

---
_Source: https://npm.io/package/react-router-async-component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
