bootiful-media-mogul / mogul-service

0 stars 1 forks source link

Vue.js URLs should not trigger http requests #25

Closed joshlong closed 2 months ago

joshlong commented 2 months ago

Is there a way to get the vue.js urls to start with # so they’re not picked up by the underlying web server when somebody hits enter on the manipulated URLs were sent

from Starbucks

Yes, the configuration I described works in modern versions of Vue.js, including Vue 3. The hash mode for routing is still supported in the latest versions of Vue Router, which is used with both Vue 2 and Vue 3.

For Vue 3 with Vue Router:

In Vue 3, the setup for Vue Router is slightly different, but the concept remains the same. You can configure hash mode as follows:

import { createRouter, createWebHashHistory } from 'vue-router'
import Home from './views/Home.vue'
import About from './views/About.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: About
  }
]

const router = createRouter({
  history: createWebHashHistory(), // This sets up the hash mode
  routes
})

export default router

Explanation:

Additional Notes:

This will work seamlessly in your Vue 3 application to prevent server-side GET requests for different routes.