【问题标题】:why does React.js doesn't display my component separately in a new window?为什么 React.js 不在新窗口中单独显示我的组件?
【发布时间】:2021-11-15 05:47:55
【问题描述】:

我是 React.js 的新手,我的第一个项目是我的投资组合网站。 所以我让索引页面呈现所有组件,但我想在新窗口中单独呈现 Resume 组件。 这是代码:

    import {
  Navbar,
  Home,
  Projects,
  Aboutme,
  Contact,
  Footer,
  Resume,
} from "./imports";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";

function App() {
  return (
    <Router>
      <div id="app">
        <Navbar />
        <Home />
        <Projects />
        <Aboutme />
        <Contact />
        <Footer />
        <Switch>
          <Route exact path="/resume">
            <Resume />
          </Route>
        </Switch>
      </div>
    </Router>
  );
}

export default App;

提前谢谢你。

【问题讨论】:

  • 请添加错误/屏幕截图,说明您在问题中没有实现的目标。

标签: reactjs routes frontend components jsx


【解决方案1】:

我也是 react.js 的新手,但我认为您需要这样的东西:

  <Router>
    <div id="app">
      <Switch>
        <Route exact path="/">
          <Navbar />
          <Home />
          <Projects />
          <Aboutme />
          <Contact />
          <Footer /> 
        </Route>
        <Route exact path="/resume">
            <Resume />
        </Route>
      </Switch>
    </div>
  </Router>

【讨论】:

  • 谢谢它的工作,我也试图弄清楚如何在“/”路径下包含渲染的组件,这就是你所做的,非常感谢
  • @SoulaimaneELManioui 很高兴,它有帮助。
猜你喜欢
  • 2020-06-13
  • 2018-06-08
  • 1970-01-01
  • 2018-08-27
  • 2019-06-14
  • 2013-02-09
  • 2015-07-15
  • 1970-01-01
  • 2022-08-13
相关资源
最近更新 更多