【问题标题】:front slash changes to back slash after ## 后正斜杠变为反斜杠
【发布时间】:2021-12-31 02:59:31
【问题描述】:

你好,我正在做这个电子项目,我遇到了这个问题,当我给出这条路径时

`file://${path.join(__dirname, `../build/index.html#/view/${arg}`)}`

我希望如此,

file:///C:/Users/admin/AppData/Local/Programs/electrondesktop/resources/app.asar/build/index.html#/view/61995a6fcf31f7cddedcce59

相反,我明白了,

file:///C:/Users/admin/AppData/Local/Programs/electrondesktop/resources/app.asar/build/index.html#\view\61995a6fcf31f7cddedcce59

请注意在井号 (#) 符号之后正斜杠 ("/") 如何变为反斜杠 ("\")

index.html#/view/61995a6fcf31f7cddedcce59

index.html#\view\61995a6fcf31f7cddedcce59

我该如何解决这个问题?

我正在使用带有反应 btw 的电子。

【问题讨论】:

  • arg 只是一个包含这个值“61995a6fcf31f7cddedcce59”的变量,它还能工作吗? @pilchard
  • 嗯,那么不确定。无法在特定于 Windows 的 MacOS 上重现此行为?
  • Windows @pilchard
  • 试过了,一点帮助都没有。必须有某种解决方案。 @pilchard

标签: javascript html node.js reactjs electron


【解决方案1】:

想出了答案!

显然,还有另一种方法可以避免 # 后出现斜线

是这样的,

url.format({
         pathname: path.join(__dirname,`index.html`),
         protocol:'file',
         slashes:true,
         hash:`#/view/61995a6fcf31f7cddedcce59`
       })

__dirname 给出了我需要的路径。即file:///C:/Users/admin/AppData/Local/Programs/electrondesktop/resources/app.asar/build/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-14
    • 2016-08-07
    • 2015-01-27
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    相关资源
    最近更新 更多