Is the removal of the Vue-Router link happening when you click on the top app bar icon in Google Material

Review of the following code snippet:

<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
        <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
        <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/icon?family=Material+Icons">
        <link rel="stylesheet" type="text/css" href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css">
        <script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    </head>
    <body>
        <div id="app">
            <aside class="mdc-drawer mdc-drawer--modal">
                <div class="mdc-drawer__content">
                    <router-link to="/" v-on:click.native="dclick">
                        <span class="mdc-list-item__graphic material-icons" aria-hidden="true">file_copy</span>
                        <span class="mdc-list-item__text">name1</span>
                    </router-link>
                    <router-link to="/bar" v-on:click.native="dclick">
                        <span class="mdc-list-item__graphic material-icons" aria-hidden="true">file_copy</span>
                        <span class="mdc-list-item__text">name2</span>
                    </router-link>
                </div>
            </aside>
            <div class="mdc-drawer-scrim"></div>
            <div class="mdc-drawer-app-content">
                <div>
                    <header class="mdc-top-app-bar mdc-top-app-bar--fixed">
                        <div class="mdc-top-app-bar__row">
                            <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
                                <a href="#" class="demo-menu material-icons mdc-top-app-bar__navigation-icon">file_copy</a>
                                <span class="mdc-top-app-bar__title">Title</span>
                            </section>

                        </div>
                    </header>
                    <div class="mdc-top-app-bar--fixed-adjust">
                        <router-view></router-view>
                    </div>
                </div>
            </div>
        </div>
        <style>
            body {
                margin:0;
            }
        </style>
        <script>
            Vue.component('A', {
                template : "<div>A</div>"
            });
            Vue.component('B', {
                template : "<div>B</div>"
            });
            var vm = new Vue({
                el: "#app",
                router : new VueRouter({
                    routes : [
                        { path: '/', component: Vue.component("A")},
                        { path: '/bar', component: Vue.component("B")}
                    ]
                }),
                data : {},
                mounted : function() {
                    this.drawer = mdc.drawer.MDCDrawer.attachTo(document.querySelector('.mdc-drawer'))
                    var drawer = this.drawer;

                    var topAppBar = mdc.topAppBar.MDCTopAppBar.attachTo(document.querySelector(".mdc-top-app-bar"));
                    topAppBar.setScrollTarget(document.querySelector(".mdc-top-app-bar").parentNode);
                    topAppBar.listen('MDCTopAppBar:nav', function (event) {
                        drawer.open = !drawer.open;
                    });
                },
                methods : {
                    dclick : function() {
                        this.drawer.open = !this.drawer.open;
                    }
                }
            });
        </script>
    </body>
</html>

I am implementing Google's Material Design Web components like topAppBar and Drawer along with Vue/Vue Router for changing views when links in the drawer are clicked.

An issue arises where clicking on name2 within the drawer to navigate to

/#/bar</code, then attempting to open the drawer by clicking the top app bar icon results in the link reverting back to <code>/
.

Seeking guidance on resolving this challenge. Thank you!

Answer №1

Make sure to set a charset in your html first and foremost, as neglecting this could lead to issues down the line, especially when things start to escalate. Also, pay attention to element B in your code (Line 33):

<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
    <a href="#" class="demo-menu material-icons mdc-top-app-bar__navigation-icon">file_copy</a>
    <span class="mdc-top-app-bar__title">Title</span>
</section>

I simply removed 'href="#"' and everything returned to normal. It's important to ensure you're utilizing material.io with VueJS correctly, or consider using more Vue-friendly material frameworks. Keep in mind that integrating third-party technologies to manipulate the DOM outside of Vue's scope can lead to complications.

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

Chrome debug function named "Backbone" triggered

Backbone provides the capability to activate functions in other classes by utilizing Backbone.Events effectively. a.js MyApp.vent.on("some:trigger", function(){ // ... }); b.js function test(){ doSomething(); MyApp.vent.trigger("some:trig ...

`Firebase Role Administration`

Currently in the process of developing a web platform using Vue.js + Firebase. I am looking to incorporate user role assignment to effectively manage Firebase rules. Users are able to sign up for this platform through 3 different forms located in 3 separat ...

Can one manipulate the simulation to make isTrusted=true a reality?

Is there a way to simulate an isTrusted=true in touchStart event triggering? Are there any libraries or workarounds that can make this achievable? When I run the touchStart event programmatically versus physically triggering it, the output differs. Below ...

jquery to create a fading effect for individual list items

I have a group of items listed, and I would like them to smoothly fade out while the next one fades in seamlessly. Below is the code I've been working on: document.ready(function(){ var list_slideshow = $("#site_slideshow_inner_text"); ...

How can I use appendChild to place two different elements into a single div?

While exploring similar questions on this topic, I have unfortunately not come across a solution that works for me. My challenge is trying to insert two a elements inside of a newly created div element using appendChild. However, I am unable to append them ...

Exploring sub-properties within objects in v-data-table

Currently, I am facing a situation where I need to pass an object as the value for all columns in my v-data-table. Instead of the usual format like this: { name: 'Ice cream sandwich', calories: 237, fat: 9.0, carbs: 37 } I want ...

Preventing the default behavior using event.preventDefault() does not seem to be effective when submitting a

Why is the event.preventDefault() method not functioning properly? <script type="text/javascript" src="vue.js"></script> <div id="app"> <form v-on:submit.prevent="saveData"> <input type="text" name="test"> <button ...

What is the best way to extract user input from a bootstrap search bar and integrate it into an ajax request to fetch information?

I am currently utilizing HTML, Javascript, and bootstrap to develop a web application. However, I have encountered an obstacle. When using the code document.getElementById("input here"), it only returned an array of 0. My goal is to retrieve data from an A ...

Is it possible that adding html tables together could result in the numbers being concatenated instead of summed?

When attempting to calculate the total sum of values in an html table column, my variable seems to be returning concatenated strings instead of the actual sum. For example, instead of 1 + 2 + 3 = 6, I am getting 1 + 2 + 3 = 123. The values in the "votes" ...

Error message: "When using Webpack 4 with Bootstrap, a TypeError occurs where property 'jquery' is read as undefined."

I've recently delved into the world of webpack and everything seems to be running smoothly. However, when I run my webpack app, I encounter the following error within Bootstrap: var version = $.fn.jquery.split(' ')[0].split('.'); ...

Output the information retrieved from the Axios call

How can I display data fetched from axios in a table? In my controller: public function index() { return User::latest(); } Inside user.vue: export default { data() { return { users: {}, } }, methods: { loadUsers() { a ...

Guide to implementing a datepicker on a webpage using Laravel

I am having trouble displaying the datepicker using the code below in my Laravel 4.2 application on Firefox. Is there a better way to display datepickers? Are there any CDNs available for this purpose? <table class="table table-striped"> <t ...

What is the best way to manage a new Error in Node.js while utilizing ES6 Symbols?

In my node.js application, I am implementing an endpoint using ES6 Symbols. Here is an example: // ES6 Symbol Method const taskCreationMethod = { [Symbol.taskMethod]() { return { storeCheckFunc: async function(storeId, employeeId) ...

A guide on adjusting a function to pause execution until a line is complete

In the code snippet below, there is an angularJS function named myFunc: $scope.myFunc = () => { myModule.getConfig().update(params); myModule.go(); myModule.log('ok'); }; Additionally, there is a go function defi ...

Add an element to the input field

Two input buttons are available for users to upload files. <input type="file" id="fileUpload" name="files" multiple><br/> <div id="selectedFiles"></div> The selected files will be appende ...

Retrieve values from an array of objects using their corresponding keys

I have an array populated with various objects containing different key-value pairs. I need to extract specific values from the array and determine if a certain value is present or not. function groupByName (contract) { const { age } = contract; const g ...

Tips for obtaining the current date in the head of a Next.js application

My goal is to utilize Date.now() within a script tag inside the head section. The code snippet I am using is as follows:- import Link from "next/link"; import Head from "next/head"; export default function IndexPage() { return ( ...

Stop the WebGL Three.js container from capturing scroll events

I am working on a full-screen three.js application which serves as the background and I am trying to add overlaid text that can be scrolled. However, my issue arises from the fact that the three.js WebGL container intercepts all scroll events and prevents ...

Tips for dynamically updating the value of a variable in Vue by importing a JavaScript file

There is a file for an app that imports ymaps.js where YmapsComponent.vue is declared. import '../js/ymaps.js'; import { createApp } from 'vue'; const app = createApp({}); import YmapsComponent from './components/YmapsComponent.vue ...

What is the best way to center align my horizontal subnav?

I am currently working on a horizontal navbar with horizontal submenus. One issue I am facing is getting the elements in mysubnav to align centrally instead of being pushed to the left all the time. If you need a visual representation of what I mean, plea ...