简体   繁体   English

如何在中打开反应组件<main>使用 react-burger-menu 时?</main>

[英]How to open a react component in <main> when using react-burger-menu?

Here is my code.是我的代码。

I am using react-burger-menu to implement the sidebar.我正在使用react-burger-menu来实现侧边栏。

The sidebar is working properly.侧边栏工作正常。

My problem is how to open the Home or GG within the tag?我的问题是如何在标签内打开HomeGG

Now, when I click the link the browser shows the component content correctly, however, the sidebar disappears.现在,当我单击链接时,浏览器会正确显示组件内容,但是,侧边栏会消失。

I want to keep the sidebar when I browse different component.当我浏览不同的组件时,我想保留侧边栏。

is it possible?可能吗?

would you tell me if other modules can do so?你能告诉我其他模块是否可以这样做?

thank you very much非常感谢您

It works if you change your App.js to this:如果您将App.js更改为以下内容,它将起作用:

import GG from "./GG";
import Home from "./Home";
import Main from "./Main";
import React from "react";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import "./style.css";    
import Sidebar from "./sideBar/SideBar";

export default function App() {
  return (
    <Router>
      <Sidebar pageWrapId={"page-wrap"} outerContainerId={"app"} />
      <Switch>
        <Route exact path="/" component={Main} />
        <Route exact path="/home" component={Home} />
        <Route exact path="/gg" component={GG} />
      </Switch>
    </Router>
  );
}

and remove the following from Main.js :并从Main.js中删除以下内容:

 <Sidebar
        pageWrapId={"page-wrap"}
        outerContainerId={"app"}
 />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM