Ionic Vue: Router Link isn’t working/doing anything - vue.js

I’m developing an app and getting some of the basics down, however, when I copy the tutorial I’m using and copied the official documentation example, I can’t get router link to work at all, it does nothing. I have no idea what I’m doing wrong but it neither make a component clickable or leads anywhere. I know the pages I’ve linked to work and are reachable because I’ve gotten to them by changing the url while testing on Google Chrome. Here is my code.
First Page I’m navigating from
> <template> <base-layout page-title="Student List/MainTemp">
> <ion-list>
> <ion-item router-link="/studentList/1">Billy Click click Click click</ion-item>
> <ion-item>Michael</ion-item>
> <ion-item>Gabby</ion-item>
> <ion-item>Nick</ion-item>
> <ion-item>Virginia</ion-item>
> </ion-list>
> <ion-button router-link="/studentListTest.vue" :router-animation="myAnimation">Click Me</ion-button> </base-layout>
> </template>
>
> <script>
> import { IonButton, IonList, IonItem } from "#ionic/vue";
> export default {
> IonButton, IonList, IonItem
> };
> </script>
Pages I’m tring to navigate to:
<template>
<base-layout>
<h2>the student details</h2>
</base-layout>
</template>
<script>
export default {
}
</script>
Second Test Page
<template>
<base-layout page-title="Student List Test">
<ion-list>
<ion-item router-link="/studentList/1">Jimmyyy tick tick Click click</ion-item>
<ion-item>Michaasdfel</ion-item>
<ion-item>Gabbasdfy</ion-item>
<ion-item>Nickasdf</ion-item>
<ion-item>West Virginia</ion-item>
</ion-list>
<ion-button router-link="/" :router-animation="myAnimation">Click zzMe</ion-button>
</base-layout>
</template>
<script>
import {
IonButton,
IonList,
IonItem
} from "#ionic/vue";
export default {
IonButton,
IonList,
IonItem
};
</script>
Router index.js
import { createRouter, createWebHistory } from '#ionic/vue-router';
import studentList from '../pages/studentList.vue';
import studentListTest from '../pages/studentListTest.vue';
const routes = [
{
path: '/',
redirect: '/studentList'
},
{
path: '/studentList',
component: studentList
},
{
path: '/studentListTest',
component: studentListTest
},
{
path: '/studentList/1',
component: () => import('../pages/studentDetails.vue')
}
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
export default router
And the base-layout for extra context
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title> {{ pageTitle }} </ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<slot />
</ion-content>
</ion-page>
</template>
<script>
import {
IonPage,
IonHeader,
IonTitle,
IonToolbar,
IonContent,
} from "#ionic/vue";
export default {
props: {
pageTitle: String
},
IonPage,
IonHeader,
IonTitle,
IonToolbar,
IonContent,
};
</script>

Vue Router renders the current paht's component in the router-view component.
Include <router-view></router-view> where you want the content to render.

I got an answer somewhere else I'll post here.
I didn't include this in the script section.
components: {
**insert components here**
}
And that prevented it from working, so here's the script section fixed
<script>
import { IonButton, IonList, IonItem } from "#ionic/vue";
import baseLayout from "#/components/base/baseLayout.vue"; (I exported this globally but I'll include it here anyway)
export default {
components: {
baseLayout,
IonButton,
IonList,
IonItem,
},
};

Related

CKEditorError: ckeditor-duplicated-modules while adding plugins to ckeditor

I'm trying to add text-alignment plugin to my ckeditor build in vue js.
Following is my code for the same::
<template>
<div>
<nav-bar />
<div id="app">
<ckeditor :editor="editor" v-model="editorData" :config="editorConfig" class="full-width"></ckeditor>
</div>
<router-view class="fixed-center"></router-view>
</div>
</template>
<script>
import NavBar from "components/NavBar.vue";
import ClassicEditor from "#ckeditor/ckeditor5-build-classic"
import Alignment from "#ckeditor/ckeditor5-alignment"
export default {
components: { NavBar },
name: "app",
data() {
return {
editor:ClassicEditor,
editorData:'<p>Content of the editor.</p>',
editorConfig:{
plugins:[Alignment],
toolbar:['Heading','bold', 'italic','alignment']
}
};
},
methods: {},
};
</script>
I'm getting following error ::
CKEditorError: ckeditor-duplicated-modules

the switching of the Vue Router is not working

I have a menu with 2 buttons. But the switching is not working. Moreover, the main page is invisible.
My sandbox https://codesandbox.io/s/serene-neumann-mpqs0?file=/src/App.vue
This is router.js
const routes = [
{
path: "/",
component: Main
},
{
path: "/history",
component: History
},
{
path: "/favorites",
component: Favorites
}
];
const router = new VueRouter({
routes
});
export default router;
This is Header
<template>
<header class="sticky top-0 z-40 w-full flex bg-yellow-500 md:h-16 shadow-md">
<div class="w-1/4 flex justify-end">
<router-link to="/favorites">
<button title="Favorites" class="p-2 hover:text-red has-tooltip">
Favorites
</button>
</router-link>
<button class="p-2 hover:text-red" title="History">
<router-link to="/history"> History </router-link>
</button>
</div>
</header>
</template>
App.vue
<template>
<Header/>
<router-view></router-view>
</template>
<script>
import Header from './components/Header.vue'
export default {
name: "App",
components: {
Header
},
};
</script>
and main.ts
import { createApp } from "vue";
import App from "./App.vue";
import "./assets/index.css";
import router from "./router";
const app = createApp(App);
app.use(router);
app.mount("#app");
You have kind of a mix between vue-router v3/v4.
Update everything to the latest versions and adapt the Router, so it works according to the latest docs should work:
https://codesandbox.io/s/keen-morning-rufbo?file=/src/router.js

Can't resolve component import VueJS

I'm trying to use MainNavbarButton within MainNavbar. I imported the component, but get the error of "Module not found: Error: Can't resolve './components/MainNavbarButton.vue'" All the solutions I found seem to stem from a spelling mistake, but I'm pretty sure that's not the case here.
MainNavbar.vue
<template>
<div id="navbar">
<MainNavbarButton />
</div>
</template>
<script>
import MainNavbarButton from './components/MainNavbarButton.vue'
export default {
name: 'MainNavbar',
components: {
MainNavbarButton
}
}
</script>
MainNavbarButton.vue
<template>
<h2>{{ title }}</h2>
</template>
<script>
export default {
name: 'MainNavbarButton',
props: {
title
}
};
</script>
App.vue
<template>
<MainNavbar/>
</template>
<script>
import MainNavbar from './components/MainNavbar.vue'
export default {
name: 'App',
components: {
MainNavbar
}
}
</script>

ion-icon not showing an icon in ionic vue

I created a blank Ionic Vue project and have the following view where I added an ion-icon element and also the IonIcon import:
<template>
<ion-page>
<ion-header :translucent="true">
<ion-toolbar>
<ion-title>Blank</ion-title>
</ion-toolbar>
</ion-header>
<ion-content :fullscreen="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">Blank</ion-title>
</ion-toolbar>
</ion-header>
<div id="container">
<strong>Ready to create an app?</strong>
<ion-icon name="home-outline"></ion-icon>
</div>
</ion-content>
</ion-page>
</template>
<script lang="ts">
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonIcon } from '#ionic/vue';
import { defineComponent } from 'vue';
export default defineComponent({
name: 'Home',
components: {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar,
IonIcon
}
});
</script>
But i still can not see the Icon, and im also not getting any error.
You need to import IonIcon component and individual icons seperately as below
in template
<ion-icon :icon="caretUpOutline" />
// please note, not like this <ion-icon name="caretUpOutline"></ion-icon>
import { IonIcon } from "#ionic/vue";
import { caretUpOutline, caretDownOutline } from "ionicons/icons";
export default {
name: "test",
components: { IonIcon },
setup() {
return { caretUpOutline }
}
Try to do so, it helps me and install this package https://www.npmjs.com/package/ionicons
<template>
<ion-page>
<ion-header :translucent="true">
<ion-toolbar>
<ion-title>Blank</ion-title>
</ion-toolbar>
</ion-header>
<ion-content :fullscreen="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">Blank</ion-title>
</ion-toolbar>
</ion-header>
<div id="container">
<strong>Ready to create an app?</strong>
<ion-icon :icon="homeOutline"></ion-icon>
</div>
</ion-content>
</ion-page>
</template>
<script lang="ts">
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonIcon } from '#ionic/vue';
import { defineComponent } from 'vue';
import {homeOutline} from 'ionicons/icons';
export default defineComponent({
name: 'Home',
components: {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar,
IonIcon
},
data(){
return {
homeOutline,
}
}
});
</script>

Do not show up the bootstrap icon even import BIcon

In my nuxt.js bootstrap-vue project:
I follow github to use bootstrap icon:
the link
my code:
<b-icon variant="success" icon="arrow-up"></b-icon>
<b-icon variant="success" icon="alert-triangle"></b-icon>
<b-icon icon="alert-circle-fill" variant="success"></b-icon>
<h2 class="group_title">Anime Wallpapers</h2>
...
<script>
import { BIcon, BIconArrowUp } from 'bootstrap-vue'
export default{
data(){
return {
msg: 'hello vue'
}
},
components: {
BIcon
}
}
</script>
but there do not shows up it:
You imported BIcon and registered it, but you didn't register the requested individual icons.
try this:
<b-icon variant="success" icon="arrow-up"></b-icon>
<b-icon icon="alert-circle-fill" variant="success"></b-icon>
<h2 class="group_title">Anime Wallpapers</h2>
...
<script>
import { BIcon, BIconArrowUp } from 'bootstrap-vue'
export default{
data(){
return {
msg: 'hello vue'
}
},
components: {
BIcon,
BIconArrowUp // <- The icon needs to be registered with your page/app
}
}
</script>
Refer to the docs that mention that you need to import individual icons: https://bootstrap-vue.org/docs/icons#usage