[英]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 .例如,就我而言,我的第一页包含两个按钮Configuration和User 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.