我知道这里有多个类似的问题,但是没有一个合适的解决方案(对我没有一个作用)。
我只是停留在这一点上,找不到任何解决方案,需要帮助!
注释
index.js
文件(应用入口点)
// index.js
//----------------------------------------
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route} from 'react-router-dom';
import {Provider} from 'react-redux';
import Store from './store';
import Home from '../components/home';
const App = () => (
<Provider store={Store}>
<Router>
<Home/>
</Router>
</Provider>
)
ReactDOM.render(
<App/>,
document.getElementById('root')
);
home.js
index.js
(文件上方)中提到的唯一组件
// home.js
//----------------------------
import React, { Component } from 'react';
import {Switch, Route, Link} from 'react-router-dom';
import {connect} from 'react-redux';
import Signup from './signup';
import Login from './login';
class Home extends Component{
render(){
return(
<Switch>
<Route exact path='/' component={Signup}/> // Case (1)
<Route exact path='/signup' component={Signup}/> // Case (2)
<Route exact path='/login' component={Login}/> // Case (3)
</Switch>
)
}
}
export default connect(null, null)(Home)
signup.js
具有 <Link>
实现的简单视图
import React, {Component} from 'react';
import {Link} from 'react-router-dom';
import {connect} from 'react-redux';
class Signup extends Component{
render(){
return(
<div>
<Link to='/signup'>Link to Signup</Link> // For Route Case (2) in signup.js
</div>
)
}
}
export default connect(null, null)(Signup)
因此,当应用启动时:
signup.js
,并带有链接-“链接到注册” (网址:localhost:8080
)"/"
触发localhost:8080
-工作正常! localhost:8080/signup
)-工作正常! localhost:8080/signup
)-错误! "Cannot GET /signup"
"/signup"
-错误! "Cannot GET /signup"
"/login"
-总是错误 "Cannot GET /login"