登录.js
import React from 'react'
export default class Login extends React.Component {
componentWillMount(){
import ('./styles/login_page.css');
}
....
<Link to="/register">Create account</Link>
}
注册.js
import React from 'react''
export default class Register extends React.Component {
componentWillMount(){
import ('./styles/register_page.css');
}
....
<Link to="/login">Login Now</Link>
}
应用程序.js
import React from 'react'
import ReactDOM from 'react-dom'
import { Route, Switch, BrowserRouter } from 'react-router-dom'
import Login from './Login'
import Register from './Register'
import PageNotFound from './PageNotFound'
ReactDOM.render(
<BrowserRouter>
<Switch>
<Route exact path='/login' component={Login }/>
<Route exact path='/' component={Home} />
<Route exact path='/register' component={Register }/>
<Route component={PageNotFound} />
</Switch>
</BrowserRouter>,
document.getElementById('root'));
渲染后,我单击登录,然后单击创建帐户并再次单击登录,登录组件的 CSS 被注册组件的 CSS 覆盖,主页是相同的。我想在访问任何组件时,组件的 CSS 正在加载。有办法修复吗?
慕桂英546537
相关分类