删除 Vue Router 中的尾部斜杠

Lan*_*nsi 6 vue.js vue-router

const routes = [
  {
    path: '/:year',
    component: Nav,
    children: [
      { path: '', name: 'test', component: Test }
    ]
  }
];
Run Code Online (Sandbox Code Playgroud)
<!-- /2018/ -->
<router-link :to="{name: 'test', params: {year: 2018}}"></router-link>
Run Code Online (Sandbox Code Playgroud)

如果有孩子,我想删除添加到路由器链接创建的路径的尾部斜杠。

cla*_*pas 0

在 Vue-Router v4 中,您可以使用以下strict选项:

const router = createRouter({
  history: createWebHistory(),
  routes: [
      ...
  ],
  strict: true, // applies to all routes
})
Run Code Online (Sandbox Code Playgroud)

查看敏感和严格的路线选项。