Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React路由器未在重定向上加载组件_Javascript_Node.js_Reactjs_Express_React Router - Fatal编程技术网

Javascript React路由器未在重定向上加载组件

Javascript React路由器未在重定向上加载组件,javascript,node.js,reactjs,express,react-router,Javascript,Node.js,Reactjs,Express,React Router,我正在尝试将组件加载到:http://localhost:3001/api/posts/success 我的路线树如下所示: import SuccessMessage from './components/SuccessMessage'; <div> <Router> <Route component={Navbar} /> <Switch> <Route exact

我正在尝试将组件加载到:http://localhost:3001/api/posts/success

我的路线树如下所示:


import SuccessMessage from './components/SuccessMessage';


<div>
      <Router>
        <Route component={Navbar} />
        <Switch>
            <Route exact path="/" component={Home} />
            <Route exact path="/api/posts/:city" component={ViewPost} />

            <Route exact path="/api/posts/item/:id" component={ItemDetails} />
                    <Route exact path="/api/posts/success" component={SuccessMessage} />
                    <Route exact path="/api/posts/termsofservice" component={termsOfService} />
            <Route exact path="/createpost" component={CreatePost} />

        </Switch>
      </Router>
    </div>
正在导出的模块

import React from 'react';
import { Jumbotron, Button  } from 'react-bootstrap';

const SuccessMessage = () => {
    return (
        <Jumbotron>
            <h1>Post Successfully Submitted!</h1>
            <p>
                Your post will be reviewed to ensure it does not violate our Terms Of Service, upon approval it will be
                displayed on the main page. Edit or Delete your post in your User Settings.
            </p>
            <p>
                <Button variant="primary" onClick={() => (window.location = `http://localhost:3001/api/posts`)}>
                    >Go To Listings
                </Button>
                {'  '}
                <Button variant="primary" onClick={() => (window.location = `http://localhost:3001/api/posts/termsofservice`)}>
                    Read Our T.O.S
                </Button>
            </p>
        </Jumbotron>
    );
};

export default SuccessMessage;

当我点击页面时,我只看到导航栏


编辑:解决方案是,当我们有一个wildroute:city时,它将阻止所有其他路线,请注意

<Route exact path="/api/posts/:city" component={ViewPost} />

编辑:解决方案是,当我们有一个wildroute:city时,它将阻止所有其他路线,请注意

<Route exact path="/api/posts/:city" component={ViewPost} />

因此,对于wildroutes,请确保将其区分开来

<Route exact path="/api/posts/city/:city" component={ViewPost} />

没有重定向,您必须在JSX中返回一个元素,即返回是否是导致问题的唯一路由?这项服务有效吗?