Embed Vue applications within the container of the main Vue application

My goal is to establish a foundational Vue application that offers essential features such as signing in, navigating with a sidebar, and the flexibility to interchange navbar items. I envision creating separate Vue applications for each navbar item.


Main concept: The plan is to provide a REST API and a fundamental container (Vue app) capable of rendering other Vue apps within a specific div element. This setup will enable others to incorporate their own frontend apps and interact with the API if needed. Instead of creating numerous apps from scratch, the primary objective is to develop a highly modular administration system with a seamless Plug and Play system. A registration process will be implemented for custom apps, allowing the API to recognize these apps along with their base URLs so that my base app can retrieve them.

https://i.sstatic.net/3qQBl.png


Setting up the base app

The base app will have a route for custom apps

{
  path: '/app/*',
  component: CustomAppContainer,
},

and will display this view

<template>
  <div id="customAppContainer">Render custom apps here</div>
</template>

The navbar will contain a link /app/one to navigate and render the 'one' app in the customAppContainer.


Configuring custom apps

When defining routes for custom apps, the base URL needs to be specified

export default new Router({
  base: '/one/',
  routes: [
    {
      path: '/',
      component: Home,
    },
  ],
});

In the main.js, updating it like this may be necessary

new Vue({
  router,
  render: h => h(CustomAppContainer),
}).$mount('#customAppContainer');

However, the challenge lies in ensuring that the app recognizes the CustomAppContainer and #customAppContainer.


Another consideration is how to distribute when only having some index.html files and needing to integrate one into another. How can a base app be deployed so that when a user wants to access a custom app via /app/myCustomApp, it gets mounted into the customAppContainer?

An example akin to this scenario is illustrated in Nextcloud

During Vue app development, running it as a standalone entity is feasible. However, for production purposes, the plan involves moving files from the dist folder into an apps directory. Upon launching the base container application, it should automatically detect all sub-applications present.

If more details are required, please feel free to request!

Answer №1

1

There seems to be an issue with Vue recognizing CustomAppContainer

Try adding

import CustomAppContainer from "path/to/CustomAppContainer.vue"
in a .vue file.


2

Vue is not able to recognize #customAppContainer

The selector should be in index.html. If your selector is within CustomAppContainer, try adding something like

<div id="#app"></div>
in index.html (usually in /public folder) and replace .$mount('#customAppContainer'); with .$mount('#app');.


3

VUE router needs the <router-view> tag. Try using this markup:

<!-- In the template, all page content goes here -->
<template>
  <!-- Navigation section -->
  <nav>
    <!-- Router links that render as "a" elements -->
    <router-link to="/one">Go to /one</router-link>
    <!-- Alternatively, standard HTML tags can also be used -->
    <a href="/two">Go to /two</a>
  </nav>
  <!-- The chosen component picked by the router will go here (Home.vue) -->
  <router-view/>
</template>

4

Router.js requires an import:

import Home from "path/to/the/Home.vue"
export default new Router({
  base: '/one/',
  routes: [
    {
      path: '/',
      component: Home,
    },
  ],
});

If everything looks okay, you're good to go!

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 process for setting default parameters using a recompose, lifecycle HOC?

I've created a custom recompose, lifecycle HOC: import { lifecycle } from 'recompose'; export function myHoc(title) { return lifecycle({ componentDidMount() { console.log(title) } }); } export default my ...

The issue of transform scale not functioning properly in conjunction with background clip and gradients in CSS

Looking to transform a div with the transform: scale(-1,1) property while using background-clip: text on the text within it. However, this causes the text to disappear. Here's what I've attempted: .reverse { transform: scale(-1, 1); } .gr ...

Construct an array through the power of Ajax

Currently, I am facing an issue with building an array using ajax. The 'test' array is structured correctly, but the 'translations' array has a flawed structure (as seen in my console output). In Chrome console: In Edge console: In F ...

The type 'string | undefined' cannot be assigned to type 'string'

I am facing a challenge in comparing two arrays, where one array is sourced from a third-party AWS service and its existence cannot be guaranteed. Despite my efforts to handle potential errors by incorporating return statements in my function calls, I con ...

Creating a wrapper function for the map method in React

When attempting to incorporate a parameter into my map function in React, I encountered an issue where the return value turned null after encapsulating it within another function. This became apparent during debugging, especially when using console.log(mar ...

What could be the reason for the CORS failure when making requests from an HTTPS domain to an HTTP localhost

I have a secure rest service (implemented as an Azure Function), hosted on HTTPS, under domain A. My website is also running securely on HTTPS but on domain B. I've set the CORS to use a wildcard *. Using jQuery on my website, I send Ajax requests ...

JavaScript failing to load following PHP header() redirect

I've set up a page that allows users to sign in by filling out a basic form, which then sends the data to a separate PHP script for validation. After the validation process is complete, the PHP script uses the header() function to redirect the user to ...

The Jquery ajax call encountered an error due to a SyntaxError when trying to parse the JSON data, specifically finding an unexpected character at

I've developed a web application that utilizes just four scripts for dynamic functionality. Overview: Init.php = Database, index.php = webpage, api.php = fetches data from server/posts data to server, drive.js = retrieves information from api.php a ...

Make sure to clear the timeout in JavaScript before re-calling the function again

Scenario: Whenever a user clicks on a cell within the "#test" table, the "update_func" function will run and repeat every 10 seconds. If the user clicks on the same cell or another cell, multiple instances of "update_func" start running simultaneously ev ...

Leverage the `dispatch` hook within a useEffect function

When it comes to triggering an action upon the React component unmounting, I faced a challenge due to hooks not allowing the use of componentWillUnmount. In order to address this, I turned to the useEffect hook: const dispatch = useDispatch(); useEffect(( ...

Choose a division of an element within an embedded frame

Two different pages on the same website, Home.html and Page2.html. Home.html contains the following code: <html> <iframe id="one" src="page2.html" style="display:none"></iframe> <div id="container"> <h1& ...

Unable to store object data within an Angular component

This is a sample component class: export class AppComponent { categories = { country: [], author: [] } constructor(){} getOptions(options) { options.forEach(option => { const key = option.name; this.categories[k ...

Accessing external content within our webpage

Previously, I utilized iframes to display an external page within our asp.net page. However, I have now decided to explore alternative methods that do not involve iframes. My goal is to open an external page within our page using only a simple aspx page wi ...

Is there a method in Kalendae js that automatically triggers the closing of the calendar after a date has been selected?

Currently, I am using Kalendae from https://github.com/ChiperSoft/Kalendae and I have to say it is fantastic. The best part is that I don't have to worry about dependencies. By default, the calendar pops up when a text box is selected and updates the ...

Having trouble getting a Mocha test to display two decimal places in Javascript? Both Big and Decimal libraries are causing issues

After encountering an error with the Big library, I decided to switch to Decimal. First, I ran npm install Decimal Then, I added the following code: const Decimal = require('decimal'); Even after following the examples, my comparison returned { ...

Ways to retrieve information and functions from defineExpose in Vue

`I am attempting to call a method from a child component within the parent component in Vue using the composition API. I have defined the method inside defineExpose, but I am unable to access it in the parent component. Hero.vue (ChildComponent) <templ ...

Ensure that when you click on the next dropdown menu opener button, the previous dropdown menu closes and only the new menu remains open

Take a look at this page first to get an understanding: On this page, I have implemented multiple dropdown menus that should open when clicked on their respective opener buttons (3 bar icon) and close either when clicked again or anywhere else on the page ...

What are the benefits of using React.useMemo or React.useCallback within component props?

Exploring efficient ways to implement TailwindCSS in React, considering its utility-first nature leading to component-heavy code (e.g. className="w-full bg-red-500"). One approach is creating a utility function like: utils/tailwind.ts const tw = (...clas ...

Is it necessary to configure modules using app.use in every route in express.js?

I recently learned that it is best practice to include the express module individually in each route file, rather than globally in app.js. Now I'm questioning whether I need to duplicate all the app.use statements in each route file or if I can just ...

Looking to learn how to replicate data effortlessly with either javascript or jquery?

I am currently trying to figure out how close I am to successfully cloning this div. Honestly, I am a bit lost at this point and could really use some assistance. Should I consider using jQuery for this task? <div id="question20">20. Details of Chi ...