iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim
MIT License
6.67k stars 277 forks source link

浏览器跳转url,页面无法刷新 #635

Closed wty20060888 closed 6 months ago

wty20060888 commented 8 months ago

Describe the bug 插件可正常预览,但在浏览器中无法进行刷新

To Reproduce Steps to reproduce the behavior:

  1. :MarkdownPreview浏览器自动跳转至 url为localhost:xxxx/1,可以正常预览
  2. 浏览器端按F5刷新,网页404
  3. 浏览器网址栏输入http://localhost:xxxx/page/1 可恢复预览,但网页URL,跳转至localhost:xxxx/1,这时再次刷新,与Step2青铜相同

Expected behavior A clear and concise description of what you expected to happen.

Screenshots Jan-03-2024 16-07-11

Desktop (please complete the following information):

Log:

cybaol commented 5 months ago

这个问题解决了吗?

wty20060888 commented 5 months ago

@cybaol 已经解决了 修改router.js文件,增加以下代码

// /:number
use((req, res, next) => {
  const number = req.asPath.slice(1); // 获取路径中的数字部分
  if (/^\d+$/.test(number)) {
    const newUrl = `/page/${number}`;
    res.writeHead(301, { Location: newUrl }); // 重定向到新的路径
    res.end();
  } else {
    next();
  }
});
zhaozg commented 5 months ago

@iamcco 请问这个改动可否合并到版本中呢

wty20060888 commented 5 months ago

@zhaozg 有时间我会提个repo

JunYang-tes commented 4 months ago

去掉这行也行: https://github.com/iamcco/markdown-preview.nvim/blob/a923f5fc5ba36a3b17e289dc35dc17f66d0548ee/app/pages/index.jsx#L123

没发现有其它影响