我有一个使用react构建的网站,它使用react-router.对于某些路由,我想要提供另一个页面或静态文件,但由于所有请求都被转发到反应路由器,因此它不起作用.
例如
www.myapp.com/sitemap.xml
www.myapp.com/something.html
^这些链接第一次工作,但是一旦我加载网站然后它不起作用,因为所有请求通过反应路由器.
任何使其始终有效的解决方案.谢谢.
编辑
我正在使用配置为将所有请求重定向到index.html的apache服务器,我想这就是这种行为的原因.这是我的配置,但我不知道如何解决这个问题.
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
Run Code Online (Sandbox Code Playgroud)
更新 我尝试在答案中建议的解决方案
我的路线看起来像这样,对于something.html我正在加载ServerLoad组件
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/about" component={About} />
<Route path="something.html" component={ServerLoad} />
<Route component={NoMatch} />
</Switch>
Run Code Online (Sandbox Code Playgroud)
在ServerLoad组件的componentDidMount函数中,我做到了这一点.但它不起作用.
componentDidMount() {
window.location.reload(true);
}
Run Code Online (Sandbox Code Playgroud)
更多的 我已经安装使用create-反应,应用该项目,并通过快递服务的服务器它(像这样).我不确定我是否需要在那里进行一些设置以服务其他静态文件.
我刚刚安装了wamp服务器但是当我试图访问localhost时它无法访问我认为这是端口问题,因为wamp默认使用端口80.之后我想创建一个动态网站,我以前从未使用过php,所以我想知道如何让satarted ...谢谢
我试过另一个系统.我安装了wamp并看到localhost可以在那里访问但是当我通过调制解调器wamp服务器连接到互联网时停止工作.我对这个端口设置感到很困惑.我从我的笔记本电脑上拔下了lan电缆并重新安装了系统然后尝试了它甚至无法正常工作..我已经更改了httpd.conf文件,但它并没有帮助我
我的数据结构模式是这样的
users(
id serial primary key,
data json
);
Run Code Online (Sandbox Code Playgroud)
我想更新data密钥。
我正在使用node-postgres库,到目前为止我已经尝试过这样的事情:
pg.connect(process.env.DATABASE_URL, function(err, client, done) {
var queryString = "UPDATE users SET data =" + myNewJsonData + " WHERE id = " + userIdToEdit + ";";
client.query(queryString, function(err, result) {
done();
if (err) {
res.send("Failed to update user data ");
throw err;
} else {
res.send("Successfully updated user data!! ");
}
});
});
Run Code Online (Sandbox Code Playgroud)
这不起作用,我收到错误invalid input syntax for type json
有谁可以帮忙吗,谢谢。
在React-Native版本30中,某些图像未加载.
这是有效的
<Image style={styles.messageImage}
source={{uri:'https://facebook.github.io/react/img/logo_og.png'}}/>
Run Code Online (Sandbox Code Playgroud)
这不起作用
<Image style={styles.messageImage}
source={{uri:'http://i.imgur.com/lDz3wVn.png'}}/>
Run Code Online (Sandbox Code Playgroud)
看起来带有https链接的图像正在工作,而带http链接的图像不起作用.还有其他人面临这个问题吗?
谢谢.
有人请解释一下。
我挣扎与this.I遵循这一博客帖子https://www.davidmeents.com/blog/how-to-simply-deploy-a-react-app-on-digital-ocean/ 但所有我得到的默认页nginx或现在经过一些混乱的配置后,我得到404 not found错误。
nginx内部有两个选件1)可用的站点2)启用了站点我不确定这里哪一个是相关的。
我的配置是这样的
server {
listen 80;
server_name 139.59.25.228;
root /www/mywebsite/app/build;
rewrite ^/(.*)/$ $1 permanent;
location / {
try_files $uri index.html;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢 -:)
reactjs ×2
apache ×1
express ×1
image ×1
javascript ×1
nginx ×1
node.js ×1
php ×1
port ×1
postgresql ×1
react-native ×1
react-router ×1
wamp ×1