Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ngozistephen's avatar

Structure my Vue Components

Hi, Everyone i am new to vue js 3, i am finding it hard to structure my components in my app.js and router.js. this is my app.js require('./bootstrap');

import { createApp } from 'vue'; import router from './router'; import App from './App.vue'; import HeaderArea from './components/HeaderArea.vue'; import LoginPage from './components/Auth/LoginPage.vue'; import RegisterPage from './components/Auth/RegisterPage.vue';

const app = createApp({}) app.component('app', App); component('header-area', HeaderArea); component('login-page', LoginPage); component('register-page', RegisterPage)

.use(router)

app.mount("#app");

this is my router.js

import Vue from 'vue'; import { createWebHistory, createRouter } from "vue-router"; import App from '@/components/App.vue'; import RegisterPage from '@/components/Auth/RegisterPage.vue'; import LoginPage from '@/components/Auth/LoginPage.vue'; import AdminDashboard from '@/components/AdminDashboard.vue';

createRouter({

history: createWebHistory(), routes: [ { path: '/', name: 'landing', component: 'LandingPage' }, { path: '/register', name: 'Register', component: 'RegisterPage' }, { path: '/dashboard', name: 'Dashboard', component: 'AdminDashboard' }, { path: '/login', name: 'Login', component: 'LoginPage' }, ] });

export default router;

0 likes
2 replies
rodrigo.pedra's avatar

I tried cleaning up a bit, it is not clear what issue you are having:

app.js

import './bootstrap';
import {createApp} from 'vue';
import router from './router';
import App from './App.vue';
import HeaderArea from './components/HeaderArea.vue';

const app = createApp({});
app.component('app', App);
app.component('header-area', HeaderArea);

app.use(router);
app.mount('#app');

router.js

import {createRouter, createWebHistory} from 'vue-router';
import LandingPage from './components/Auth/LandingPage.vue';
import RegisterPage from './components/Auth/RegisterPage.vue';
import LoginPage from './components/Auth/LoginPage.vue';
import AdminDashboard from './components/AdminDashboard.vue';

createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            name: 'landing',
            component: LandingPage,
        },
        {
            path: '/register',
            name: 'Register',
            component: RegisterPage,
        },
        {
            path: '/login',
            name: 'Login',
            component: LoginPage,
        },
        {
            path: '/dashboard',
            name: 'Dashboard',
            component: AdminDashboard,
        },
    ]
});

export default router;

Also, next time wrap your code sample inside lines with either 3 tildes ( ~ ) or 3 backticks ( ` )

~~~
code goes here
~~~

or

```
code goes here
```

Please or to participate in this conversation.