0
我有一個應用程序位於我的主域的子文件夾內。因此,Test.com是我的域名,我的應用程序位於該域名稱爲「Player」的文件夾中,即Test.com/player。反應路由器4指向主域不子文件夾
問題是React Router需要指向Test.com/player時指向Test.com。
另一個問題是我的索引文件位於名爲'public'的文件夾中。
如何在React Router 4/htacess中執行此操作?
感謝
應用
import React from "react";
import {render} from "react-dom";
import {BrowserRouter, Route, Switch, hashHistory} from "react-router-dom";
import Nav from "./components/Nav";
import Home from "./components/Home";
import About from "./components/About";
import Contact from "./components/Contact";
class App extends React.Component {
render() {
return (
<BrowserRouter history={hashHistory}>
<div>
<Nav />
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
<Route render={() => {
return <h1>Not Found!</h1>
}} />
</Switch>
</div>
</BrowserRouter>
);
}
}
render(<App />, document.getElementById("main"));
的WebPack
const webpack = require("webpack");
module.exports = {
entry: {
filename: "./app/app.js"
},
output: {
filename: "./app/build/bundle.js"
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
query: {
presets: ["es2015", "react"]
}
}
]
},
devServer: {
inline: true,
port: 5000,
contentBase: "./public",
historyApiFallback: true,
}
}
首頁組件的工作原理和頁面刷新的作品,但是當我點擊進入我最初加載的頁面或聯繫頁面,但在頁面刷新我只得到404. –
@JoeConsterdine我編輯了我的答案,我希望這些更改可以幫助你 – AngelSalazar