简体   繁体   English

使用反应 js_在下一页上没有路由按钮,在按钮点击时导航到全新的页面

[英]Navigate to totally new page on button click using react js_having no route buttons on next page

I have been trying to navigate from one page to another using Route/BrowserHistory but what they do is that the router buttons stay on the top of the page.我一直在尝试使用Route/BrowserHistory从一个页面导航到另一个页面,但他们所做的是将路由器按钮保留在页面顶部。 However, I want to navigate to a totally different page which does not contain that routing buttons.但是,我想导航到一个完全不同的页面,该页面不包含该路由按钮。

For example in my case, my first page consists of two buttons Configuration and User Portal .例如,就我而言,我的第一页包含两个按钮ConfigurationUser Portal On clicking any of the buttons, I want to jump to a new page ie UserPortal page on clicking User Portal .单击任何按钮时,我想跳转到一个新页面,即单击User Portal 时的UserPortal 页面。

Here is my code:这是我的代码:

<div className="App">
   <BrowserRouter>
      <div>
        <nav aria-label="breadcrumb">
          <ol className="breadcrumb" style={{background: 'none'}}>
             <div className="breadcrumb-item">
                <Link to="configuration">
                  <button className='btn btn-primary' id='config' >Configuration</button>
                </Link>
             </div>
             <div className="breadcrumb-item">
                <Link to="userPortal">
                  <button className='btn btn-primary' id='portal' >User Portal</button>
                </Link>
             </div>
          </ol>
        </nav>
        <Switch>
           <Route path="/configuration" component={ArduinoInterface} />
           <Route path="/userPortal" component={UserPortal} />
        </Switch>
     </div>
  </BrowserRouter>
</div>

What should I do to get the desired result?我该怎么做才能得到想要的结果?

Your help would be appreciated!您的帮助将不胜感激! Thanks.谢谢。

This is how I solved my problem.这就是我解决我的问题的方法。 I followed this example and it worked.我跟着这个例子,它奏效了。

Index.js索引.js

ReactDOM.render(<Router history={history}>
    <Routes />
  </Router> , document.getElementById('root'));

Routes.js路由.js

<Switch>
     <Route path="/" exact component={MainPage} />
     <Route path="/configuration" component={ArduinoInterface} />
     <Route path="/userportal" component={UserPortal} />
     <Route component={MainPage} />
</Switch>

MainPage.js主页.js

<div>
    <button type="button" id='config'><Link to='/configuration'>Configuration</Link></button>
</div>
<div >
    <button type="button" id='portal'><Link to='/userportal'>User Portal</Link></button>
</div>

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

相关问题 单击按钮时使用 React 导航到新页面 - Navigate to a new page with React when I click on a button 如何在 react js 中转到(导航)下一页 - how to go (navigate) the next page in react js 尝试使用 react js 创建一个多功能按钮 {在第一次点击时 - 保存数据,打开“查看”,然后在第二次点击时 - 导航到保存的页面} - Trying to create a multi-functional button using react js {on first click - saves data, turns “view”, and on second click - navigate to saved page} casperjs按钮单击不导航到下一页 - casperjs button click doesn't navigate to next page 在单个页面中导航的上一个和下一个按钮 - Previous and next buttons that navigate through a single page 如何使用 JS 触发下载音频链接,而无需浏览器导航到新页面? - How to trigger a download of an audio link using JS, without having the browser navigate to a new page? 在 React JS 中单击项目时导航到子文件夹中的页面 - Navigate to a page in a sub folder on item click in React JS 无法在按钮单击时在新路由上的新页面中呈现组件 - Unable to render component in a new page on a new route on button click 单击按钮导航到路线 - Navigate to route on button click 如何使用javascript以编程方式单击并导航到新页面 - How to click and navigate on a new page programatically using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM