V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
drymonfidelia
V2EX  ›  程序员

带路由模块的 SPA 跳转 id="example" 这个 div 的最佳实践是什么?例如 Angular,用 #example 直接跳转到了 ./example 这个路由

  •  
  •   drymonfidelia · 16 天前 · 779 次点击
    3 条回复    2024-10-02 19:12:02 +08:00
    MagicalCarl
        1
    MagicalCarl  
       15 天前
    const anchor = document.getElementById(`example`);
    if (anchor) {
    anchor.scrollIntoView({
    behavior: 'smooth',
    block: 'start'
    });
    }
    drymonfidelia
        2
    drymonfidelia  
    OP
       15 天前
    @MagicalCarl 这样变成要自己 handle 这个逻辑了,也没办法通过 https://xxx.com/my/page#example 这样的链接来直接分享某个章节,想找找有没有更优雅、完美的解法
    crysislinux
        3
    crysislinux  
       15 天前 via Android
    就 angular 来说应该可以只用 history api 吧,这样就不占用这个东西了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5351 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 08:30 · PVG 16:30 · LAX 01:30 · JFK 04:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.