React-Router-Dom路径的参数

时间:2018-02-01 11:50:05

标签: reactjs react-router react-router-v4

我试图使用react-router-dom路径参数包含动态链接,例如(路径:" /链接/:PARAMS&#34)。但不知何故,对此类链接的任何请求都会返回404错误。注意第三条路线。

    import React from 'react'
    import { BrowserRouter, Switch, Route } from 'react-router-dom'
    const EditExpensePage = (props) => {
      return (
        <div>
          <p>EditExpense Page with id of {props.match.params.id}</p>
        </div>
      )
    }

const AppRouter = () => (
  <BrowserRouter>

    <div>
      <Header/>
      <Switch>
        <Route path="/" component={DashboardPage} exact={true}/>
        <Route path="/create/" component={AddExpensePage}/>
        <Route path="/edit/:id" component={EditExpensePage}/>
        <Route path="/help" component={HelpPage}/>
        <Route component={NotFoundPage}/>
    </Switch>
    </div>

  </BrowserRouter>
)

export default AppRouter;

当我尝试访问链接时,例如。(localhost:8080 / edit / 43),我得到了一个空白页面,其中包含来自我的捆绑js文件的控制台中的日志:

GET http://localhost:8081/edit/scripts/app.js 404 (Not Found)

0 个答案:

没有答案