错误页面

公共组件

  1. const Errors = (props)=>{
  2. const {errors} = props
  3. if(errors){
  4. return (
  5. <ul className="error-messages">
  6. {
  7. Object.keys(errors).map(key=>{
  8. return (
  9. <li key={key}>
  10. {key} : {errors[key]}
  11. </li>
  12. )
  13. })
  14. }
  15. </ul>
  16. )
  17. }else{
  18. return null
  19. }
  20. }
  21. export default Errors

注册页面

  1. import { PureComponent } from 'react'
  2. import { Link } from 'react-router-dom'
  3. import Errors from '../../components/Errors'
  4. class Regist extends PureComponent {
  5. render() {
  6. return (
  7. <div className=' container page'>
  8. <div className='row'>
  9. {/* 注册内容 */}
  10. <div className='col-md-6 offset-md-3 col-xs-12'>
  11. <h1>注册</h1>
  12. {/* 重定向登录 */}
  13. <p className='text-xs-center'>
  14. <Link to='/login'>
  15. 有账号直接登录?
  16. </Link>
  17. </p>
  18. {/* 错误提示 */}
  19. <Errors errors={errors}/>
  20. <form>
  21. <fieldset>
  22. <fieldset className='form-group'>
  23. <input
  24. className='form-control form-control-lg'
  25. type='text'
  26. placeholder='用户名称'
  27. />
  28. </fieldset>
  29. <fieldset className='form-group'>
  30. <input
  31. className='form-control form-control-lg'
  32. type='email'
  33. placeholder='用户邮箱'
  34. />
  35. </fieldset>
  36. <fieldset className='form-group'>
  37. <input
  38. className='form-control form-control-lg'
  39. type='password'
  40. placeholder='用户密码'
  41. />
  42. </fieldset>
  43. <button
  44. className='btn btn-lg btn-primary pull-xs-right'
  45. type='submit'
  46. >
  47. 注册
  48. </button>
  49. </fieldset>
  50. </form>
  51. </div>
  52. </div>
  53. </div>
  54. )
  55. }
  56. }
  57. export default Regist;

登录页面

  1. import { PureComponent } from 'react'
  2. import { Link } from 'react-router-dom'
  3. import Errors from '../../components/Errors'
  4. class Login extends PureComponent {
  5. render() {
  6. return (
  7. <div className=' container page'>
  8. <div className='row'>
  9. {/* 登录内容 */}
  10. <div className='col-md-6 offset-md-3 col-xs-12'>
  11. <h1>登录</h1>
  12. {/* 重定向登录 */}
  13. <p className='text-xs-center'>
  14. <Link to='/regist'>
  15. 没账号直接注册?
  16. </Link>
  17. </p>
  18. {/* 错误提示 */}
  19. <Errors errors={errors}/>
  20. <form>
  21. <fieldset>
  22. <fieldset className='form-group'>
  23. <input
  24. className='form-control form-control-lg'
  25. type='email'
  26. placeholder='用户邮箱'
  27. />
  28. </fieldset>
  29. <fieldset className='form-group'>
  30. <input
  31. className='form-control form-control-lg'
  32. type='password'
  33. placeholder='用户密码'
  34. />
  35. </fieldset>
  36. <button
  37. className='btn btn-lg btn-primary pull-xs-right'
  38. type='submit'
  39. >
  40. 登 录
  41. </button>
  42. </fieldset>
  43. </form>
  44. </div>
  45. </div>
  46. </div>
  47. )
  48. }
  49. }
  50. export default Login;