detail 文件写完之后出现的错误?我是哪个地方写错了?

来源:6-5 【路由搭建】页面导航

慕UI4249796

2021-03-21

这是App.tsx 中的代码

import React from 'react';
import styles from './App.module.css';
import{BrowserRouter,Route,Switch} from "react-router-dom"
import {HomePage,SignInPage,RegisterPage, DetailPage} from "./pages"

function App() {
  return (
  <div className={styles.App}>
    <BrowserRouter>
    <Switch>
      <Route exact path="/" component={HomePage}/>
      <Route path="/signin" component={SignInPage} />
      <Route path="/register" component={RegisterPage} />
      <Route path="/detail/:touristRouteId" component={DetailPage} />
      <Route render ={()=><h1>404 not found page go to mars</h1>}/>
    </Switch>

    
    </BrowserRouter>
   
  </div>
  );
}

export default App;

这是DetailPage.tsx 中的代码。

import React from "react";
import {RouteComponentProps} from "react-router-dom"

interface MatchParams {
    touristRouteId: string;
}
export const DetailPage: React.FC<RouteComponentProps<MatchParams>> = (props)=>{
    return (
    <h1> 
        the detail of way of trail, the way ID: {props.match.params}
    </h1>
    )
}

after npm start, there is some wrong here

请帮忙看一下。 多谢多谢!

写回答

2回答

慕UI4249796

提问者

2021-03-22

已解决。。。

0
0

慕UI4249796

提问者

2021-03-21

the error

···

Error: Objects are not valid as a React child (found: object with keys {touristRouteId}). If you meant to render a collection of children, use an array instead.

···

0
0

React18 系统精讲 结合TS打造旅游电商平台

React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能

1993 学习 · 1015 问题

查看课程