javascript - Serve another(standalone) page or static file in website built with react -
i have website built react, uses react-router. route want serve page or static file, since request forwarded react router, doesn't work.
for example
www.myapp.com/sitemap.xml
www.myapp.com/something.html
^ these link works first time, once load website doesn't work, request goe through react router.
any solution make work time. thanks.
edit
i'm using apache server configured redirect request index.html, guess reason behaviour. configuration, don't know how fix this.
options -multiviews rewriteengine on rewritecond %{https} off rewriterule (.*) https://%{http_host}%{request_uri} [r,l] rewritecond %{request_filename} !-f rewriterule ^ index.html [qsa,l]
update tried solution suggested in answer.
my routes looks this, something.html loading serverload component
<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>
in serverload component's componentdidmount function did this. doesn't work.
componentdidmount() { window.location.reload(true); }
more have setup project using create-react-app, , serving express server(like this). i'am not sure if need setting there server other static files.
this should work:
const reload = () => window.location.reload(); <router> // routes.. ... // special routes.. <route path="/sitemap.xml" onenter={reload} /> <route path="/something.html" onenter={reload} /> </router>
so, think should pretty clear ;)
update:
if option can put target="_blank" attribute in <link>
imho ux perspective better, because if these routes not part of main application, user can switch tab after visiting special pages.
Comments
Post a Comment