skip to Main Content

I develop with laravel9 and vue3.

My problem is simple, But path setting is not go well.

When I access url localhost:8080/tasks

This url return 404 not found and I get the following type error

GET http://localhost:8000/tasks 404 (Not Found)

I didn’t know the reason , but When I rewrite path: /tasks to path /, localhost:8080 return Component that I want to need.

I have following files.

router.js

import { createRouter, createWebHistory } from "vue-router";
import TaskListComponent from "./components/TaskListComponent.vue";


const router = createRouter({
    history: createWebHistory(),
    routes: [

        {
            path: '/tasks',
            name: 'tasks.list',
            component: TaskListComponent
        }
    ]
})

export default router

App.vue

<script setup>
import HeaderComponent from "./components/HeaderComponent.vue";
</script>

<template>
    <HeaderComponent />
    <router-view></router-view>
</template>

bootstrap.js

import { createApp } from "vue";
import App from "./App.vue";
import router from "./router.js"

const app = createApp(App);

app.use(router);

app.mount("#app");

2

Answers


  1. I created a project using Vue’s CLI, then proceeded to check all the relevant parts.

    I took your code and applied the various changes:

    • my entry point is main.js, rather than bootstrap.js but no changes code-wise
    • in App.vue, I don’t have any HeaderComponent but it’s should not be an issue anyway
    • in router/index.js, I only changed the following for the component since it’s better to use an alias than a relative path anyway
    import TaskListComponent from "@/components/TaskListComponent.vue"
    

    Launching the server with

    pnpm dev
    

    gives me some port, once followed to the /tasks path, I can see the component as expected.

    enter image description here

    The route is properly defined too

    enter image description here

    Here is my project directory

    enter image description here

    And I don’t have any errors in the console.


    Here is public github repo: https://github.com/kissu/so-v3-working-router

    Login or Signup to reply.
  2. The following in web.php fixed the issue

    Route::get('{any?}', function () {
        return view('welcome');
    })->where('any', '.*');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search