Javascript 无法查看关于页面路由的信息,但由于缺少,无法访问主页路由<;脚本>;
我似乎不明白为什么我不能访问我的“关于”页面。我可以进入我的Javascript 无法查看关于页面路由的信息,但由于缺少,无法访问主页路由<;脚本>;,javascript,ecmascript-6,redux,react-router,react-router-v4,Javascript,Ecmascript 6,Redux,React Router,React Router V4,我似乎不明白为什么我不能访问我的“关于”页面。我可以进入我的主页,但不能进入我的关于页面。当我查看开发人员工具时,在localhost:3000中,我看到了带有的主页内容。但是,在localhost:3000/about中,我没有看到!它丢失了包裹 App.js import React from 'react'; import Header from './common/Header'; import Footer from './common/Footer'; import {Switch,
主页
,但不能进入我的关于页面
。当我查看开发人员工具时,在localhost:3000
中,我看到了带有
的主页内容。但是,在localhost:3000/about
中,我没有看到
!它丢失了包裹
App.js
import React from 'react';
import Header from './common/Header';
import Footer from './common/Footer';
import {Switch, Route} from 'react-router-dom';
import HomePage from './home/HomePage';
import AboutPage from './about/AboutPage';
class App extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {};
}
render() {
return (
<div>
<Header/>
<Switch>
<Route exact path="/" component={HomePage}/>
<Route path="/about" component={AboutPage}/>
</Switch>
<Footer/>
</div>
);
}
}
export default App;
从“React”导入React;
从“./common/Header”导入标题;
从“./common/Footer”导入页脚;
从“react router dom”导入{Switch,Route};
从“./home/HomePage”导入主页;
从“./about/AboutPage”导入AboutPage;
类应用程序扩展了React.Component{
构造函数(道具、上下文){
超级(道具、背景);
this.state={};
}
render(){
返回(
);
}
}
导出默认应用程序;
AboutPage.js
import React from 'react';
class AboutPage extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {};
}
render() {
return(
<div>
about pagesdfsdf
</div>
);
}
}
export default AboutPage;
从“React”导入React;
类AboutPage扩展了React.Component{
构造函数(道具、上下文){
超级(道具、背景);
this.state={};
}
render(){
返回(
关于pagesdfsdf
);
}
}
导出默认值约为页;
index.js
import React from 'react';
import {render} from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import {Provider} from 'react-redux';
import configureStore from './store/configureStore';
import App from './components/App';
const store = configureStore();
render(
<Provider store={store}>
<BrowserRouter>
<App/>
</BrowserRouter>
</Provider>,
document.getElementById('app')
);
从“React”导入React;
从'react dom'导入{render};
从“react router dom”导入{BrowserRouter};
从'react redux'导入{Provider};
从“/store/configureStore”导入configureStore;
从“./components/App”导入应用程序;
const store=configureStore();
渲染(
,
document.getElementById('app')
);
需要更多设置-您有服务器吗?您可能想切换到
,因为它更容易启动和运行。至少,它会解决您现在遇到的问题,并使您的代码正常工作
请参考此处的差异:我假设您正在为应用程序使用webpack。 因此,为了使BrowserRouter工作,您必须在webpack.config.js中提供以下配置 在输出部分
output: {
filename: 'app.bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath : '/' // set the public path to root
}
在服务器部分
devServer: {
hot : true,
contentBase: path.join(__dirname, "dist"),
historyApiFallback : true, // set the historyApiFallback to true
compress: true,
port: 8080
}
您需要添加React Router Redux:-)您如何在路由之间移动?你的环境怎么样?@Win正在调查。反应路由器dom(v4)+redux。网页包作为构建工具。仅使用Express提供前端代码。Django as Api您认为我需要像建议的那样
react router redux
?我在和reduxnah打交道-没有它你会没事的。