如何避免在仪表板刷新页面后返回登录菜单或主页



我构建我的网站并创建所有组件,如主页、仪表板、登录名等,当我登录仪表板并在保存后创建其他菜单时,页面再次返回到登录屏幕或主页,创建新代码后,它总是再次返回主页或登录屏幕,如何避免?

父类包括减速器

import React from 'react'
import { render } from 'react-dom'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import { Route} from 'react-router-dom';
import {Router, Switch} from 'react-router';
import { createHashHistory } from 'history';
import LandingLayout from './layouts/LandingLayout.js';
import App from './containers/App'
import reducer from './reducers'
import Login from './containers/Login'
import Browse from './containers/Browse'
import Home from './containers/Home'
import About from './containers/About'
import Contact from './containers/Contact'
import Input from './containers/Input'
import Detail from './containers/Detail'
const store = createStore(reducer);
const customHistory = createHashHistory();
render(
<Provider store = {store}>
<Router history={customHistory}>
<div>
<Switch>
<Route exact path='/' render={() => <LandingLayout><App /></LandingLayout>}/>
<Route exact path='/Home' render={() => <LandingLayout><Home /></LandingLayout>}/>
<Route exact path='/Input' render={() => <LandingLayout><Input /></LandingLayout>}/>
<Route exact path='/Detail' render={() => <LandingLayout><Detail /></LandingLayout>}/>
<Route exact path='/About' render={() => <LandingLayout><About /></LandingLayout>}/>
<Route exact path='/Contact' render={() => <LandingLayout><Contact /></LandingLayout>}/>
<Route exact path='/login' render={() => <LandingLayout><Login /></LandingLayout>}/>
<Route exact path='/browse' render={() => <LandingLayout><Browse /></LandingLayout>} />
</Switch>
</div>
</Router>
</Provider>,
document.getElementById('root')
)

对于这种情况,有两种解决方案:

1(登录后使用target="_blank"打开一个无法返回上一页的新选项卡:)

2(使用历史记录包:history.replace('/dashboard')

最新更新