black11black
V2EX  ›  问与答

Vue 框架写的项目,如何优雅的实现伪静态?

  •  
  •   black11black · May 31, 2020 · 2167 views
    This topic created in 2178 days ago, the information mentioned may be changed or developed.

    如题,比如如果用 vue 实现个人博客,如果网址是

    https://my.blog/artical/32

    看起来光秃秃的很丑,如果末尾加上.html,变成

    https://my.blog/artical/32.html

    迷之看起来就舒服多了。

    我知道 vue-router 可以实现捕获后缀,比如这个例子里如果要捕获 32.html 是比较简单的,这样的话如果用一种丑陋的实现方式,比如先判断字符串末尾是否是.html,再把之前的 32 裁出来,再请求后端数据,否则跳转 404,似乎确实可以实现伪静态。

    想知道 vue 有原生的,或者其他比较优雅的实现方式吗?这个方法感觉太丑了

    2 replies    2020-06-01 09:45:28 +08:00
    yidinghe
        1
    yidinghe  
       May 31, 2020 via Android
    Nginx 的 URL 重写可以承担去掉后缀的功能,然后将无后缀的请求转发给应用服务。
    TomVista
        2
    TomVista  
       Jun 1, 2020
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   974 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 20:06 · PVG 04:06 · LAX 13:06 · JFK 16:06
    ♥ Do have faith in what you're doing.