最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vue.js - How to use Vue Router navigation in `url query`, not in `url path`? - Stack Overflow

programmeradmin0浏览0评论

I use Vue Router to navigate inside Vue.js SPA application. So I define routes as following:

createRouter({
    routes: [
      {
        path: '/budget/:budgetId(\\d+)?',
        name: 'budget',
        component: BudgetView,
      },
    ],
  }),

And when I navigate to 'budget' page, url changes to the following /budget/1.

But when I reload the page in static web server, I get an error Not Found. This is because resource does not exist.

So I want actually Vue Router to navigate to the following url /?path=/budget/1 in order to web server can proceed this page navigation correctly.

Something like option pathInQuery: true on Router creation.

I use Vue Router to navigate inside Vue.js SPA application. So I define routes as following:

createRouter({
    routes: [
      {
        path: '/budget/:budgetId(\\d+)?',
        name: 'budget',
        component: BudgetView,
      },
    ],
  }),

And when I navigate to 'budget' page, url changes to the following /budget/1.

But when I reload the page in static web server, I get an error Not Found. This is because resource does not exist.

So I want actually Vue Router to navigate to the following url /?path=/budget/1 in order to web server can proceed this page navigation correctly.

Something like option pathInQuery: true on Router creation.

Share Improve this question asked Feb 11 at 11:43 ilya_dtilya_dt 531 silver badge6 bronze badges 1
  • 1 Why not simply use Hash mode? It is a well-trodden path, and not much different from what you describe. – Moritz Ringler Commented Feb 11 at 12:11
Add a comment  | 

1 Answer 1

Reset to default 0

as Moritz Ringler wrote Hash mode can be used.

发布评论

评论列表(0)

  1. 暂无评论