【问题标题】:Path matches Route but the component for that route is not renderedPath 与 Route 匹配,但该路由的组件未呈现
【发布时间】:2018-07-12 10:02:02
【问题描述】:

我的路由组件是这样的:

const Workout = props => {
  console.log(props);
  return (
    <div>
      <h1>hello</h1>
    </div>
  );
};

export default Workout;

然后我将此组件导入我的 index.js

import Workout from "./views/Workout";

然后我定义我的路线

<Route exact path="/:weekId/:dayId:/work" component={Workout} />

我在浏览器中点击了路线:

codesandbox.io/week-1/day-1/work

但没有渲染,没有错误,也没有 console.log :(

【问题讨论】:

    标签: javascript reactjs react-router-v4


    【解决方案1】:

    路径变量应该是:dayId,而不是:dayId:

    示例

    const Workout = props => {
      console.log(props);
      return (
        <div>
          <h1>hello</h1>
        </div>
      );
    };
    
    function App() {
      return (
        <BrowserRouter>
          <Route path="/:weekId/:dayId/work" component={Workout} />
        </BrowserRouter>
      );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-25
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 2019-01-08
      • 1970-01-01
      相关资源
      最近更新 更多