Simple Vue.js Component to Redirect to External Web Page Using Vue Router


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Simple Vue.js Component to Redirect to External Web Page Using Vue Router

Vue Router has some quirks and on of the quirks is that it is not reliable when adding external links using the vue-router library.

After struggling with many solutions, I have found that creating a simple Vue.js component like this one seems to work the best (so far):

Component Example: RedirectNotes.vue

Code:
<template>
  <div class="d-flex justify-content-around" style="padding:20px" v-if="redirect()">
    <div>
      <h3>This Vue Component Does a Basic Redirect</h3>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    redirect() {
      var url = "https://www.unix.com/usernote.php";
      this.$router.push({ path: "/dashboard" });
      window.open(url, "_target");
    }
  }
};
</script>

<style>
</style>

Naturally the entries is routes.js are simple:

Code:
const RedirectNotes = () => import("src/pages/vB/RedirectNotes.vue");

Code:
   
       {
        path: "usernotes",
        name: "User Notes",
        components: { default: RedirectNotes }
      },

This is not the best method, but it is the only method that works consistently in vue-router so far.

The downside is that some browsers may block the new window and the user will need to grant permissions.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Vue.js component: Beautiful code highlighter
Neo
Sooner than later I will render forum discussions in Vue.js to complement the standard way of showing forum threads. Today, I ran across this component, vue-code-highlight Beautiful code syntax highlighting as Vue.js component. https://www.unix.com/members/1-albums225-picture1199.jpg ...... Web Development
1
Web Development
Vue JS 2 Tutorial by The Net Ninja: A Recommended Vue.js Video Tutorial Series
Neo
A number of people have asked me how to get started with Vue.js and my reply before today was to Google "Vue.js". That has changed and my recommendation to anyone who wants to learn the fastest growing, easiest to learn and use Vue.js web dev framework is to watch this video tutorial series: ...... Web Development
0
Web Development
MySQL Query to Build Mockup Vue.js UserCP Timeline Page
Neo
Here is the query (and some sample results) I plan to use to build a new timeline page in the mockup vue.js usercp I am working on. When the postid is the same as lastpostid, this means the timeline entry will be - "{{Member}} Started Discussion {{Thread Title}} at {{date and time}}" and when...... Web Development
4
Web Development
A simple UNIXtime component in Vue.js
Neo
A shout out to Scott who gave me a helping hand to turn a simple sample Vue.js app I wrote yesterday into a Vue.js component: Vue.component("unix-time", { template: `<div class="time">{{unixtime}}</div>`, data() { return { unixtime: "" }; }, methods: { ...... Web Development
1
Web Development
A Simple Way to Set Meta Tags Using Vue.js
Neo
Did a lot of searching on the net and found a lot of tricky ways and Vue.js libs to set meta tags, but I wanted sometime simpler. So, given this standard HTML: <head> <title>Page Title</title> <meta name="description" content="Page Description"> <meta name="keywords" content="Page...... Web Development
0
Web Development
Red Hat Linux

Red Hat, Inc. is a global American software company providing open-source software products to the enterprise community. Red Hat was Founded in 1993, and has its corporate headquarters in Raleigh, North Carolina, with other offices worldwide. On October 28, 2018, IBM announced its intent to acquire Red Hat for $34 billion. Red Hat has focused on Red Hat Enterprise Linux an enterprise operating system. Red Hat also acquired the open-source enterprise middleware vendor JBoss. Red Hat also sells an enterprise virtualization product, Red Hat Virtualization (RHV). Red Hat also provides storage, operating system platforms, middleware, applications, management products, and support, training, and consulting services. Red Hat actively creates, maintains, and contributes to many free and open software projects. Red Hat has acquired several proprietary software products through corporate mergers and acquisitions and has released these software acquisitions under open-source licenses.
Please enjoy and help our forum community by "showing your work" and posting your code, even when your code is not working as expected. To help others help you, please wrap your code blocks, sample input, sample output, error messages, and other data in CODE tags and wrap your short commands and short data objects in ICODE tags. We were all beginners in the beginning. If you have any questions about how to register or how to post, please contact us in Live Chat. Thank you and enjoy this "forever free" technical support community for UNIX, Linux and computer information technology in general.