skip to Main Content

Let me start of with the fact that im new to laravel and english is not my main language so dont mind my grammer. I have a project that has a laravel api with a vue front-end. The Laravel web routing redirects everything to a single blade file that contains the vue app. this way i can use the vue routing. This is has all been working fine for a while now but now im trying to build for production and ive run into the following issue.

after using npm run build to build for production laravel puts /build/ to every route im using through vue. This is very logical given that it uses the build folder in the public directory like it should. But its ofcourse verry ugly for the users. Is there a way to remove the /build/ from the url? (appart from redirecting /build/ to / in the .htacces file on the server)

2

Answers


  1. Problem from import.meta.env.BASE_URL in vitejs, in build mode this import.meta.env.BASE_URL result "/build/" and development mode result, is "/"

    I don’t know where to change this, but I fix this problem with

    const router = createRouter({
    history: createWebHistory("/"),
    routes: [
        {
         ......
        }
    ]
    

    })

    and fix it

    Login or Signup to reply.
  2. You can set the environment variables in .env file for javascript using VITE_ prefix as below:

    Please add the new environment variable in .env file as below:

    VITE_BASE_URL="/"
    

    Made the router related changes in your Vue file as below:

    const router = createRouter({
      history: createWebHistory(import.meta.env.VITE_BASE_URL || '/'),
      routes: [
        .....
      ],
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search