我的父组件中包含以下代码:
class App extends Component {
render() {
return(
<Router>
<div>
<Route exact path='/' component={Main} />
<Route path="/login" component={Login} />
</div>
</Router>
);
}}
这在主要组件中:
import React, { Component } from "react";
import {BrowserRouter as Router, Route, Link } from 'react-router-dom'
class Main extends Component {
render() {
return (
<Router>
<section className="section main">
<div className="container">
<div className="main-titles-container">
<div className="main-titles">
<div className="yellow-square"></div>
<h1>Title</h1>
<p>
Introduction
</p>
<div className="button-container">
<Link to='/login' className="btn select bg-yellow" id="buyer">Next</Link>
</div>
</div>
</div>
</div>
</section>
</Router>
);
}
}
export default Main;
登录:
import React, { Component } from 'react';
class Login extends React.Component {
constructor(props) {
super(props);
this.state = {
email: "",
cellphone: ""
}
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e) {
const target = e.target;
this.setState({
[target.name]: target.value
});
}
handleSubmit(e) {
e.preventDefault();
console.log(this.state);
}
render() {
return (
<section className="section">
<div className="container center center-xy">
<h1 className="title center-self">Title</h1>
<h1 className="title center-self">Log in</h1>
<div className="form-container">
<form onSubmit={this.handleSubmit}>
<label htmlFor="email">Email</label>
<input type="text" name="email" id="email" onChange={this.handleChange} defaultValue="" required/>
<label htmlFor="cellphone">Cell phone</label>
<input type="text" name="cellphone" id="cellphone" defaultValue="" onChange={this.handleChange} required/>
<button className="bg-yellow center-self" type="submit">Ok</button>
</form>
</div>
</div>
</section>
);
}
}
export default Login;
单击时,我想重定向到“登录”页面,但是问题是,当我单击该“按钮”时,URL更改为“ /登录”,但未呈现相应的组件。但是,如果我使用“ / login” URL刷新页面,则会呈现该组件。 感谢您的任何事先帮助!
编辑:我不使用PureComponent,并且在withRouter中包装导出内容也不能解决我的问题。
答案 0 :(得分:2)
仅应使用顶级组件(在您的情况下为 >> MySQLTuner 1.7.5 - Major Hayden <major@mhtx.net>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.60-MariaDB
[OK] Operating on 64-bit architecture
-------- Log file Recommendations ------------------------------------------------------------------
[--] Log file: /var/log/mariadb/mariadb.log(45K)
[OK] Log file /var/log/mariadb/mariadb.log exists
[OK] Log file /var/log/mariadb/mariadb.log is readable.
[OK] Log file /var/log/mariadb/mariadb.log is not empty
[OK] Log file /var/log/mariadb/mariadb.log is smaller than 32 Mb
[!!] /var/log/mariadb/mariadb.log contains 1 warning(s).
[!!] /var/log/mariadb/mariadb.log contains 16 error(s).
[--] 31 start(s) detected in /var/log/mariadb/mariadb.log
[--] 1) 181116 0:49:26 [Note] /usr/libexec/mysqld: ready for connections.
[--] 2) 181109 8:28:59 [Note] /usr/libexec/mysqld: ready for connections.
[--] 3) 181109 8:00:12 [Note] /usr/libexec/mysqld: ready for connections.
[--] 4) 181106 23:47:13 [Note] /usr/libexec/mysqld: ready for connections.
[--] 5) 181106 1:22:22 [Note] /usr/libexec/mysqld: ready for connections.
[--] 6) 181029 11:05:08 [Note] /usr/libexec/mysqld: ready for connections.
[--] 7) 181009 9:49:46 [Note] /usr/libexec/mysqld: ready for connections.
[--] 8) 180929 22:48:02 [Note] /usr/libexec/mysqld: ready for connections.
[--] 9) 180827 3:40:02 [Note] /usr/libexec/mysqld: ready for connections.
[--] 10) 180723 23:24:44 [Note] /usr/libexec/mysqld: ready for connections.
[--] 31 shutdown(s) detected in /var/log/mariadb/mariadb.log
[--] 1) 181116 0:48:02 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 2) 181109 8:28:57 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 3) 181109 8:00:09 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 4) 181106 23:47:09 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 5) 181106 1:21:09 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 6) 181029 11:04:05 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 7) 181009 9:48:37 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 8) 180929 22:46:58 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 9) 180827 3:40:00 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 10) 180723 23:23:45 [Note] /usr/libexec/mysqld: Shutdown complete
-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +Aria +BLACKHOLE +CSV +FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in MyISAM tables: 836M (Tables: 100)
[--] Data in InnoDB tables: 28M (Tables: 356)
[OK] Total fragmented tables: 0
-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] There is no basic password file list!
-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined
-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 3d 13h 42m 42s (528K q [1.714 qps], 143K conn, TX: 3G, RX: 67M)
[--] Reads / Writes: 97% / 3%
[--] Binary logging is disabled
[--] Physical Memory : 2.0G
[--] Max MySQL memory : 1.6G
[--] Other process memory: 400.6M
[--] Total buffers: 1.2G global + 2.8M per thread (151 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 1.2G (61.38% of installed RAM)
[OK] Maximum possible memory usage: 1.6G (81.28% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (268/528K)
[OK] Highest usage of available connections: 5% (8/151)
[OK] Aborted connections: 0.00% (1/143266)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[OK] Query cache efficiency: 46.5% (202K cached / 436K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 3% (57 temp sorts / 1K sorts)
[OK] No joins without indexes
[!!] Temporary tables created on disk: 70% (12K on disk / 17K total)
[OK] Thread cache hit rate: 99% (50 created / 143K connections)
[!!] Table cache hit rate: 9% (400 open / 4K opened)
[OK] Open file limit used: 21% (224/1K)
[OK] Table locks acquired immediately: 99% (63K immediate / 63K locks)
-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema isn't installed.
-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 2 thread(s).
[--] Using default value is good enough for your version (5.5.60-MariaDB)
-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 75.7% (25M used / 33M cache)
[OK] Key buffer size / total MyISAM indexes: 32.0M/238.8M
[OK] Read Key buffer hit rate: 100.0% (1B cached / 79K reads)
[OK] Write Key buffer hit rate: 100.0% (18K cached / 18K writes)
-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[!!] InnoDB File per table is not activated
[OK] InnoDB buffer pool / data size: 756.0M/28.3M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (1.32275132275132 %): 5.0M * 2/756.0M should be equal 25%
[OK] InnoDB buffer pool instances: 1
[--] InnoDB Buffer Pool Chunk Size not used or defined in your version
[OK] InnoDB Read buffer efficiency: 99.91% (2333138 hits/ 2335267 total)
[!!] InnoDB Write Log efficiency: 2.25% (33 hits/ 1469 total)
[OK] InnoDB log waits: 0.00% (0 waits / 1436 writes)
-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/1B
[OK] Aria pagecache hit rate: 99.6% (96K cached / 359 reads)
-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.
-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.
-------- RocksDB Metrics ---------------------------------------------------------------------------
[--] RocksDB is disabled.
-------- Spider Metrics ----------------------------------------------------------------------------
[--] Spider is disabled.
-------- Connect Metrics ---------------------------------------------------------------------------
[--] Connect is disabled.
-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.
-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] This is a standalone server.
-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Control warning line(s) into /var/log/mariadb/mariadb.log file
Control error line(s) into /var/log/mariadb/mariadb.log file
Dedicate this server to your database for highest performance.
Enable the slow query log to troubleshoot bad queries
Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries which have no LIMIT clause
Increase table_open_cache gradually to avoid file descriptor limits
Read this before increasing table_open_cache over 64: (bit.ly removed)
Beware that open_files_limit (1024) variable
should be greater than table_open_cache (400)
Consider installing Sys schema from https://github.com/mysql/mysql-sys
Read this before changing innodb_log_file_size and/or innodb_log_files_in_group: (bit.ly removed)
Variables to adjust:
query_cache_size (=0)
query_cache_type (=0)
tmp_table_size (> 16M)
max_heap_table_size (> 16M)
table_open_cache (> 400)
innodb_file_per_table=ON
innodb_log_file_size should be (=94M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
)来呈现App
组件。其下的所有组件(例如Router
)在render函数中都不应包含Main
。他们将继承父母的Router
。您仍然可以在子组件内部使用Router
或Link
组件,它们将导航父Route
。