【问题标题】:How to make createObjectUrl() work with react-router?如何使 createObjectUrl() 与 react-router 一起工作?
【发布时间】:2019-05-26 09:54:54
【问题描述】:

window.createObjectUrl() 创建一个形状为blob:http://domain/generatedString 的 URL,我正在尝试在 <iframe> 中使用此 URI,但它似乎不起作用,因为如果没有任何规则,react-router 会将我重定向到主页匹配,因为它有一个像这样的开关:

<Switch>
  <Route exact path="/" component={Home} />
  <Route exact  path="/a" component={A} />
  <Route exact  path="/b" component={B} />
  <Route component={nomatch} />
</Switch>

如何为这些 blob URI 之一制定规则?

编辑:好的,答案不是 react-router,而是其他东西弄乱了我的 blob。可悲的是,我不记得那是什么了。但是,嘿,现在你知道它不是 react-router :+)

【问题讨论】:

    标签: react-router react-router-v4 react-router-dom


    【解决方案1】:

    当您在浏览器中打开链接时,不要忘记您的网址前面的blob:

    不要尝试: http://domain/generatedString

    但是 blob:http://domain/generatedString

    所以你的 react 应用程序不会被调用,react router

    【讨论】:

      【解决方案2】:

      对我来说,它在 JSX 中是这样工作的:

      const url = window.URL.createObjectURL(someData)
      const downloadLink = React.createElement('a', { download: 'filename.csv', href: url}, 'download')
      
      return (downloadLink)
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-30
        • 2018-12-17
        • 2019-05-04
        • 2016-08-20
        • 1970-01-01
        • 2016-07-30
        • 1970-01-01
        • 2018-07-13
        相关资源
        最近更新 更多