Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

React bindings for Ultra router

License

NotificationsYou must be signed in to change notification settings

gt3/react-ultra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Provides ancillary components to useUltra in React apps.

  1. <Ultra /> - creates Ultra container and provides it to children via context.
  2. <Use /> - dynamically adds and removes route configuration (matchers) as the component mounts and unmounts.
  3. <A /> - creates an anchor link element to trigger pushstate.
downloaddependencies
0.9 kbultra, react, prop-types

Usage

Quick example to demonstrate code splitting (webpack dynamic import) withreact-ultra components.

// app.jsimport{Ultra,A}from'react-ultra'import{spec,match}from'ultra'letdynamicImport=()=>import(/* webpackChunkName: "news" */'./news')letNews,Nav,App,renderApp,rootMatchNav=()=><div><Ahref="/news">news home</A><Ahref="/news/sports">sports</A><Ahref="/news/politics">politics</A></div>App=({ path}={})=>{letshowNews=path&&path.indexOf('/news')===0if(showNews&&!News){dynamicImport().then(module=>{News=module.defaultrenderApp({ path})})}return(<Ultramatchers={rootMatch}dispatch={false}><Nav/>{showNews&&News ?<News/> :null}</Ultra>)}renderApp=route=>React.render(<App{...route}/>,document.getElementById('root'))rootMatch=match([spec('/news')(renderApp),spec('/')(renderApp)])renderApp()

app.js is our entry point where we render the<App /> component with<Nav /> links on the page. We use<Ultra /> to initialize the router container with root level matches. We use<A /> to create anchor links to navigate to the news section.

News module is loaded dynamically using webpack import on/news path hit. The<News /> component mounts once the module is loaded.

// news.jsimport{Use}from'react-ultra'import{spec,match}from'ultra'letnext,newsMatch,Newsnext=route=>console.log('news section: ',route.path)newsMatch=match([spec('/news/sports')(next),spec('/news/politics')(next)])News=()=><div><h1>News Home</h1><Usematchers={newsMatch}dispatch={true}/></div>exportdefaultNews

The<News /> componentprepends its matchers to the router by rendering<Use />. It adds the news section matchers on mount and removes on unmount.

Try out code samples here:ultra router examples.

License

MIT

About

React bindings for Ultra router

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp