鍍金池/ 問答/HTML/ router4 的match.url是什么意思?我的這段代碼怎么實現(xiàn)路由跳轉(zhuǎn)?

router4 的match.url是什么意思?我的這段代碼怎么實現(xiàn)路由跳轉(zhuǎn)?

import React from 'react'
import {
  BrowserRouter as Router,
  Route,
  Link
} from 'react-router-dom'

const BasicExample = () => (
  <Router>
    <div>
      <ul>
        <li><Link to="/">Home</Link></li>
        <li><Link to="/about">About</Link></li>
        <li><Link to="/topics">Topics</Link></li>
      </ul>

      <hr/>

      <Route exact path="/" component={Home}/>
      <Route path="/about" component={About}/>
      <Route path="/topics" component={Topics}/>
    </div>
  </Router>
)

const Home = () => (
  <div>
    <h2>Home</h2>
  </div>
)

const About = () => (
  <div>
    <h2>About</h2>
  </div>
)

const Topics = ({ match }) => (
  <div>
    <h2>Topics</h2>
    <ul>
      <li>
        <Link to={`${match.url}/rendering`}>
          Rendering with React
        </Link>
      </li>
      <li>
        <Link to={`${match.url}/components`}>
          Components
        </Link>
      </li>
      <li>
        <Link to={`${match.url}/props-v-state`}>
          Props v. State
        </Link>
      </li>
    </ul>

    <Route path={`${match.url}/:topicId`} component={Topic}/>
    <Route exact path={match.url} render={() => (
      <h3>Please select a topic.</h3>
    )}/>
  </div>
)

const Topic = ({ match }) => (
  <div>
    <h3>{match.params.topicId}</h3>
  </div>
)

export default BasicExample
回答
編輯回答
舊言

這篇文章可以看一下 https://segmentfault.com/a/11...

 <BrowserRouter forceRefresh={!supportsHistory} keyLength={12}>
      <div >
        <Route path="/" component={aContainer} />
        <Route path="/b" component={Parent} />
        {/* {app()} */}
      </div>
    </BrowserRouter>
const Parent = ({ match }) => (
  <div>
    <Route path={`${match.url}/`} component={bContainer} />
    <Route path={`${match.url}/c`} component={cContainer} />
    <Route path={`${match.url}/d`} component={dContainer} />
  </div>
);

這里match.url其實就是Parent的path

2018年1月3日 01:48