我是新手,尝试创建带有子页面的应用程序没有问题,但我做了一个小问题,就是我的链接“ localhost:3000 / ”已转换为“ localhost:3000 /#/ “
这是我的代码:
App.js
import React, { Component } from 'react';
import Header from './layouts/header.js';
import Footer from './layouts/footer.js';
import Sidebar from './layouts/sidebar.js';
import './css/style.scss';
const App = (props) => {
return (
<div>
<div className="sideBar">
<Sidebar />
</div>
<div className="main_container">
<Header />
{props.children}
<Footer />
</div>
</div>
);
}
export default App;
routes.js
import React from 'react';
import { IndexRoute } from 'react-router';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
/**
* Import all page components here
*/
import App from './App.js';
import MainPage from './pages/homepage.js';
import About from './pages/about.js';
/**
* All routes go here.
* Don't forget to import the components above after adding new route.*/
export default (
<Route path="/" component={App}>
<IndexRoute component={MainPage} />
<Route path="/about/:id" component={About} />
</Route>
);
答案 0 :(得分:0)
尝试使用 browserHistory
import { Router, Route, browserHistory } from 'react-router';
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={MainPage} />
<Route path="/about/:id" component={About} />
</Route>
</Router>
参考: this question