Vue 路由器匹配问题

问题描述 投票:0回答:1

我正在使用 https://github.com/posva/unplugin-vue-router#readme 创建路由。 (通过 vitesse 模板)

我的文件夹结构创建了这个: https://paths.esm.dev/?p=AAMeJaCAuCDAEAg2AAUF6EpAnGgRcPaAuALjAgC4CVhNYcDgnB3YAmcKD3X4PpmGgE0KJ5QAiAIQBCACXBYgZAAA&t=/hi/asd/other#

/hi/asd 和 /hi/asd/other 与 /hi/:name 的视图匹配,基于该文件中的视图内容。

我正在使用的文件夹结构:

src/pages (folder)
src/pages/hi (folder)
src/pages/hi/[name] (folder)
src/pages/hi/[name]/other.vue
src/pages/hi/[name].vue
src/pages/[...all].vue
src/pages/about.md
src/pages/index.vue
src/pages/README.md

为什么与other.vue不匹配?

vue.js vue-router
1个回答
0
投票

路由按照定义的顺序进行匹配。 /hi/:name 路由在 /hi/:name/other 路由之前定义,因此它始终会首先匹配。

解决 只需在路由 /hi/:name 之前定义路由 /hi/:name/other 即可。 我希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.