0

I have a problem with my simple application using Vue 3, Vue router 4 & Laravel 8, my problem is that the main component is not loading I need to Ctrl + R to be able to see the main component and for the other component using Vue router nothing is loading properly this is my full code after downloading all the packages and run npm install , npm run dev & npm run watch :

app.js

require("./bootstrap");

import { createApp } from "vue";

import Main from "./components/App.vue";

import router from "./router";

const app = createApp({});

app.component("main-app", Main);

app.use(router);

app.mount("#app");

router.js

import { createRouter, createWebHistory, routerKey } from "vue-router";
import Home from "./components/pages/Home.vue";
import About from "./components/pages/About.vue";
import NotFound from "./components/pages/NotFound.vue";

const routes = [
    {
        path: "/Home",
        name: "Home",
        component: Home,
    },
    {
        path: "/About",
        name: "About",
        component: About,
    },
    {
        path: "/:catchAll(.*)",
        component: NotFound,
    },
];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes,
});

export default router;

// export default createRouter({
//     history: createWebHistory(),
//     routes,
// });

welcome.blade.php I named app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Laravel</title>

  <link rel="stylesheet" href="{{ mix('css/app.css') }}">

</head>

<body>
  <div id="app">
    <main-app />
  </div>
  <script src="{{ mix('js/app.js') }}"></script>
</body>

</html>

App.vue

<template>
    <h1>Hello from the main app</h1>
    <div id="nav">
        <router-link to="/Home">Home</router-link> |
        <router-link to="/About">About</router-link>
    </div>
    <router-veiw />
</template>
<script>
export default {};
</script>

About.vue, Home.vue & NotFound.vue They have the same code so no need to write them again in each file I change x

<template>
    <p>Hello from X component</p>
</template>
<script>
export default {};
</script>

and finally web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Back\DashboardController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// Call main path
Route::get('/', function () {
 return view('app');
});
Nadim
  • 280
  • 2
  • 12
  • 1
    you can't use self closing tags in html `` should be `` – dantheman Jul 16 '21 at 13:21
  • 1
    Also you need to update your web.php to take into account all the possible routes in your router. Otherwise the page wont load on refresh on those routes. Also your router.js dosen't have any route set for the root ie `path: "/",` – dantheman Jul 16 '21 at 13:25
  • 1
    Also a spelling mistake `` should be `` – dantheman Jul 16 '21 at 13:43
  • @dantheman Thank you so much I didn't see the spelling mistake of veiw anyway I guess the first load of the initial component it's working just fine I change already the tags to be like for the router.js I add the path: "/" but unfortunately still the router-view is not showing the other component yet. – Nadim Jul 16 '21 at 15:52
  • Also i found this warning in my console : `[Vue warn]: Failed to resolve component: router-veiw at at ` – Nadim Jul 16 '21 at 16:01
  • @dantheman working like charm bro ! thank you somuch – Nadim Jul 16 '21 at 16:35

0 Answers0