omi/packages/omi-ex/README.md

979 B

omi-ex

Omi.js ts extension by rainmanhhh

Install

npm i omi-ex

Usage

  • Supports Router/Route(react-router like)
  • Supports keepAlive
  • Sharing data with subcomponents
    • appData.routerData.query
    • appData.routerData.params
    • appData.routerData.data
import {RouterData} from 'omi-ex'

export class AppData {
  abc: string = ''
  passToChild: string = 'from parent'
  routerData: RouterData = new RouterData()
}

export const appData = new AppData()
...
...
render(props: Omi.RenderableProps<AppProps>, data: AppData) {
  return (
    <div>
      <div>
        <a href={'#/'}>home</a>
        <a href={'#/test'}>test</a>
      </div>
      <Router data={appData.routerData}>
        <Route path={'/'} keepAlive={true}><Main/></Route>
        <Route path={'/test'}><Test/></Route>
        <Route path={'*'}>Not found</Route>
      </Router>
    </div>
  )
}
...