簡體   English   中英

Vue-router:去掉 url 中的斜杠

[英]Vue-router: get rid of trailing slash in the url

設置:vue 2.6.14 & vue-router,我的路由器配置:

{
  mode:            'history',
  base:            document.location.pathname,
  routes: [
    {
      path:      '/',
      name:      'main',
      component: Main,
      props:     (route) => {
        return {
          id: route.query.id,
        };
      },
      pathToRegexpOptions: {
        strict: true,
      },
    },
  ],
}

問題:我有這樣的網址

local.host/page/xxx_111.html?id=111

路由器基礎是/page/xxx_111.html路徑。 在某些時候,我想通過編程導航將 url 更改為

local.host/page/xxx_111.html

換句話說,擺脫查詢參數,但無論我做什么,我總是得到

local.host/page/xxx_111.html/

帶有斜杠:(如何解決這個問題?

通過制作路由器的path: '/*([\\w\\-]+_?[\\d]+.html)'匹配任何類型為 local.host/<ANYTHING>/xxx_111.html 的local.host/<ANYTHING>/xxx_111.html並調用像this.$router.push({ query: {} })擺脫 url 參數,無需在 url 中添加斜杠。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM