• 请不要在回答技术问题时复制粘贴 AI 生成的内容
asiasky
V2EX  ›  程序员

有没有老哥开发过包含路由的 npm 插件

  •  
  •   asiasky · Apr 2, 2021 · 1545 views
    This topic created in 2050 days ago, the information mentioned may be changed or developed.

    现在 VUE 项目里面有个需求 要把部分功能做成一个插件直接引入 但是这个功能是包含路由的 怎么才能在引用插件的时候将插件中的路由注册到项目的路由上去

    2 replies  •  2021-04-02 15:48:29 +08:00
    BreadKiller
    BreadKiller
    Apr 2, 2021❤️1
    1
    在写插件的时候,传当前项目的 router 实例进去,然后在插件里用 router.addRoutes 注册路由
    asiasky
    asiasky
    OP
    Apr 2, 2021
    2
    @BreadKiller 好的 我试试 里面一级路由 子路由都有
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2385 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 12:57 · PVG 20:57 · LAX 04:57 · JFK 07:57
    ♥ Do have faith in what you're doing.