React 使用静态 HTML 页面作为起始页。

huangapple go评论71阅读模式
英文:

React use static html page as start page

问题

我有一个React应用程序,起始页面需要是由美术团队创建的静态HTML页面。问题是我无法让路由器从“/”重定向到静态页面:

<Redirect from="/welcome/index.html" to="/welcome/index.html" />

因为它会通过React的主页传递所有内容(由于单页应用程序的逻辑)。我尝试过创建一个包含静态页面代码的组件,但我一直收到许多错误,我不知道如何修复,因为静态页面包含许多我不熟悉的标签(我无法独自创建这个静态页面的功能)。是否有任何方法可以绕过React的单页逻辑进行重定向?

英文:

I have a React app where the start page needs to be a static html page created by the art team. The problem is that I can't get the Router to redirect from "/" to the static page

&lt;Redirect from=&quot;/&quot; to=&quot;/welcome/index.html&quot; /&gt;

because it passes everything through the React index page (due to the single page application logic). I have tried to make a component with the static page's code in, but I keep getting a lot of errors which I don't know how to fix, as the static page contains a lot of &lt;svg&gt; tags that I am not familiar with (I could not have created this static page's functionality by myself). Is there any way to do a redirect bypassing React's single page logic?

答案1

得分: 0

找到了解决方案/重定向到一个名为Welcome的组件

    <Redirect from="/" to="/Welcome" />

在Welcome组件内部我加入了

    export default function Welcome(){
      window.location.href = '/welcome/index.html';
    
      return(
        <></>
      )
    }
英文:

Found a solution. Made "/" redirect to a component called Welcome:

&lt;Redirect from=&quot;/&quot; to=&quot;/Welcome&quot; /&gt;

and inside the Welcome component I put

export default function Welcome(){
  window.location.href = &#39;/welcome/index.html&#39;;

  return(
    &lt;&gt;
    &lt;/&gt;
  )
}

huangapple
  • 本文由 发表于 2023年4月4日 16:29:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75927153.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定