Navigating with VueRouter in your Chrome Extension is a breeze

I have been working on a Chrome extension using Vue 3 + VueRouter.

One issue I encountered was trying to change the router-view content to display a different component, essentially showing users a different UI.

Despite my efforts and various methods used, I couldn't get the view to switch.

In my App.vue file, I have a router-view set up with two components that I want to alternate between - About and Home.

The initial view is Home, but when a user clicks a button, I wanted to switch to the About Page. I attempted to use router.push('/about') to achieve this, but it didn't work.

I understand that Chrome extensions don't behave like regular web pages in terms of routing, making it tricky to implement changes.

I referenced a solution on Stack Overflow and tried implementing it, but unfortunately, it didn't solve the issue.

Here is the Stack Overflow post I referred to

router.js

import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/index.html",
    component: () => import("../src/App.vue"),
    name: "App",
  },
  {
    path: "/about",
    component: () => import("../src/views/About.vue"),
    name: "About",
  },
];

const router = createRouter({
  history: createWebHashHistory("index.html"),
  routes,
});

export default router;

main.js

import { createApp } from "vue";
import App from "./App.vue";
import "./index.css";
import store from "./store/index";
import router from "./router";

const app = createApp(App);
app.use(store);
app.use(router);
app.mount("#app");

App.vue (when using router-view)

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

When I had router-view in App.vue on the Chrome extension, nothing displayed.

To attempt changing the view, I also tried using router-link, which also didn't work. Upon clicking the router-link tag, nothing happened.

<template>
 <Login />
<router-link to="/about"> About </router-link>
</template>

methods: {
  routerPush() {
      this.$router.push("about");
      this.$router.push("/about"); // tried both with and without /
    },
}

<template>
 <Login />
<span @click="routerPush"> About </span> 
</template>

I included the above code snippet to test out the router.push functionality, but unfortunately, it did not work as expected.

Answer №1

After making some adjustments, I managed to resolve the issue with Vue router not functioning properly. It turns out that the main reason for this was due to a missing renderer Vue to mount.

To fix this, you must ensure that you have a component named Renderer.vue (or any other name) which includes the necessary template and then mount that component in your main.js file by using createApp(Renderer) method.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the proper way to invoke render functions using Vue 3 composition API?

During my time with Vue 2, I would typically call render() in this manner: export default { mounted(){ ... }, render(){ ... }, methods(){ ... } } Now that I'm exploring Vue 3 and the composition API, I ...

What is the process for transferring npm package files to my local project?

Despite my efforts to find the answer, I couldn't locate it and so here I am asking again. What I'm looking for: I need to move a file from node_modules to my project in order to work on it. First attempt: I moved the file I wanted to edit An ...

The Trouble with Vue.js 2 and Axios Scopes

I previously encountered this "problem" but can't recall the correct approach to achieve the desired results. My current setup involves using Vue 2 to load data into variables that are then displayed on the HTML side: window.Vue = require('vue&a ...

Using Node.js to Send Emails via API

I've been grappling with an issue for over a week while trying to develop a web application that sends welcome emails to new subscribers. Despite my API code working perfectly, I cannot seem to get any output on the console indicating success or failu ...

"VueJs and ChartJs work together to create single file components, but the computed property is only rendered in Vue Dev Tools when the component is

Currently, I am working on a single file component that utilizes Chart.Js to display a basic visualization of some hardcoded data. The Chart.Js library is being called from a CDN placed in the head section of my index.html file. The project is based on th ...

Removing the JavaScript unicode character 8206 from a text string

I recently transitioned from VB.NET to JavaScript, and I am still getting familiar with the language. I have encountered an issue where a string I'm working with in JavaScript contains Unicode escape characters (0x5206, left-to-right mark) that I need ...

The dropdown menu in AngularJS is unable to retrieve the selected index

Presently, I have a dropdown menu: <select class="form-control" name="timeSlot" ng-model="user.dateTimeSlot" ng-change="dateTimeChanged(user.dateTimeSlot)" ng-blur="blur29=true" required style="float: none; margin: 0 auto;"> ...

Tips for effectively managing relationships in a RESTful API

Exploring the concept of REST architecture through the development of a RESTful service for an 'Issues Tracking Application'. In this application, users, projects, issues, and comments are integral components. The relationships are outlined as f ...

Switch over to TypeScript - combining Socket.IO, Angular, and Node.js

This is the code I'm using for my node server: import http from 'http'; import Debug from 'debug'; import socketio, { Server } from 'socket.io'; import app from './app'; import ServerGlobal from './serve ...

Discovering the total of varying inputs in ReactJS

//this is the API response: { "message": "success", "code": 100, "data": { "inCourseCategories": [ { "_id": "62b842f09184bf2330e6f506", "course": "601a67e6db65fb15946e6b6f ...

When attempting to submit data, the Magnific Popup page is restored to its default format

I am facing an issue with my Magnific Popup page: function dataLink(){ $.magnificPopup.open({ items: { src: 'datapage.html', type: 'ajax' }, closeOnContentClick : false, clos ...

Displaying JSON data from the API on a webpage within a NodeJS weather application

Currently, I am in the process of developing a weather application using NodeJS. I have successfully retrieved JSON formatted data from the weather site's API. Nonetheless, I am perplexed about how to transmit this data to the application. Below is a ...

Exploring the data types of dictionary elements in TypeScript

I have a model structured like this: class Model { from: number; values: { [id: string]: number }; originalValues: { [id: string]: number }; } After that, I initialize an array of models: I am trying to compare the values with the o ...

Tips for resolving the "Unexpected reserved word" error during the installation of Laravel Jetstream

I have been following the steps outlined on to set up Laravel Jetstream. Upon running artisan jetstream:install, I selected Livewire support, API support, email verification, and PHPUnit support for installation. Next, I executed npm install as per the ...

React and SASS - issue with checkbox component not being properly aligned with its label

I'm brand new to React and I'm currently in the process of converting a pure HTML page into a React component. How can I adjust the SASS stylesheet to match the original HTML layout? Here is my current React setup (the checkbox displays on the r ...

Troubleshooting Vue Router Loading Problem

After setting up the Vue router in my project, I encountered an issue where clicking on a button would change the URL parameter but the page wouldn't update. Additionally, when directly accessing the URL, the intended page wouldn't load. The src ...

Loop through JSON array within an angular controller

I am currently attempting to iterate through a JSON array and display the values on the frontend of my application. I have provided my code, but I'm having trouble retrieving specific values (startDate, endDate) from within the array and displaying th ...

Modify the h:outputText value dynamically with the power of jQuery!

Is it possible to use jQuery to dynamically change the value of my OutputText component? This is the code snippet for my component: <h:outputText id="txt_pay_days" value="0" binding="#{Attendance_Calculation.txt_pay_days}"/> I would apprecia ...

Unable to cancel $interval within factory

I created a factory for long-polling, complete with start and stop methods. However, I am struggling to cancel the timer. Any suggestions or ideas? app.controller("AuthCtrl", function($scope, $http, $window, User, Poller) { Poller.start(1, $scope.sess ...

Exploring the benefits of using virtual scrolling in conjunction with the Vuetify timeline component

Currently, I am utilizing the vuetify timeline component from the vuetify framework. Hello all, I have a demo similar to the vuetify timeline sample available at this link. The issue I am facing is that when there are a large number of items, the DOM tak ...