Excellent question! This is a very common challenge in modern web development. The short answer is that you don't use a single "framework" that is simultaneously React, Vue, and Angular. Instead, you create a framework-agnostic component using a technology that all three can understand.
The industry-standard and best solution for this is Web Components.
The Winning Strategy: Web Components
Web Components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in your web pages and web apps. Because they are a browser standard, they work natively in React, Vue, Angular, Svelte, or even plain HTML without any special configuration.
A Web Component consists of three main technologies:
Custom Elements: A set of JavaScript APIs that allow you to define your own custom HTML elements with their own logic and behavior (e.g., <my-cool-widget>).
Shadow DOM: Provides encapsulation for the component's internal DOM and styling. This means the component's CSS won't leak out and affect the rest of the page, and the page's CSS won't accidentally break your component.
HTML Templates: The <template> and <slot> elements let you write markup templates that are not rendered in the page but can be reused and instantiated later by your component.
How to Build Web Components?
While you can write Web Components with vanilla JavaScript, it's quite verbose. Most developers use a library or compiler to make it much easier and more declarative, similar to working with React or Vue.
Here are the top two choices:
1. Lit (Recommended for most cases)
Lit is a simple, lightweight library from Google for building fast, light Web Components. Its syntax will feel very familiar to React developers (it uses tagged template literals that look a lot like JSX). It's my top recommendation for this task.
Why Lit?
Lightweight: Adds only ~5KB to your bundle.
Declarative: You define your component's properties and how they render, and Lit handles the updates efficiently.
Great Tooling: Excellent support for TypeScript and a thriving ecosystem.
Backed by Google: Used extensively in many Google products.
Example of a Lit Component (simple-greeting.js):
javascript
import { LitElement, html, css } from 'lit';
import { customElement, property } from 'lit/decorators.js';
@customElement('simple-greeting')
export class SimpleGreeting extends LitElement {
// Define encapsulated styles
static styles = css`
p { color: blue; }
`;
// Define a reactive property that will trigger re-renders when it changes
@property()
name = 'Somebody';
// Define the component's template
render() {
return html`<p>Hello, ${this.name}!</p>`;
}
}
import './simple-greeting.js';
function App() {
const aName = 'React';
// It just works! Pass props like standard HTML attributes.
return <simple-greeting name={aName}></simple-greeting>;
}
In Vue:
vue
<script setup>
import './simple-greeting.js';
const aName = 'Vue';
</script>
<template>
<!-- It just works! Use v-bind for dynamic properties -->
<simple-greeting :name="aName"></simple-greeting>
</template>
In Angular:
In main.ts: import './simple-greeting.js';
In app.module.ts: add CUSTOM_ELEMENTS_SCHEMA to your @NgModule.
In app.component.html:
html
<!-- It just works! Use property binding for dynamic properties -->
<simple-greeting [name]="aName"></simple-greeting>
In app.component.ts: aName = 'Angular';
2. Stencil.js
Stencil is a compiler that generates standard-compliant Web Components. It's more of a "framework" for building component libraries. It's created by the team behind the Ionic Framework.
Why Stencil?
Compiler-based: You write components using JSX and TypeScript, and Stencil compiles them to highly optimized, lazy-loaded Web Components.
Feature-Rich: Comes with features like pre-rendering, a dev server, and a test runner out of the box.
Performance: Generates only the necessary vanilla JS for each component, making them very performant.
It's a great choice if you're building a large design system or a complex library of components intended for cross-framework use. For a single "page" or a few components, Lit is often simpler.
Alternative Architecture: Micro-Frontends
If your goal is not just to share a single component but to build a large application where different teams might use different frameworks (e.g., the search page is in React, the checkout page is in Vue), you are looking for a Micro-Frontend architecture.
This is a more advanced approach where an "app shell" or "container" application orchestrates the loading and mounting of different smaller applications.
Key Technologies for Micro-Frontends:
Module Federation: The most modern and popular approach. It's a feature of Webpack and is being adopted by other bundlers like Vite. It allows a JavaScript application to dynamically load code from another application at runtime. This is the gold standard for building micro-frontends today.
single-spa: An orchestrator library that helps you build a front-end application out of multiple independent micro-applications, regardless of their framework.
This is likely overkill if you just want to create one reusable "page" or component.
Summary Table
Approach
Technology
Best For
Pros
Cons
Framework-Agnostic Component
Lit
Creating one or more reusable components/pages for use in any framework. The best starting point.
Lightweight, simple, great developer experience, standards-based.
Passing complex data (functions, objects) can require workarounds.
Framework-Agnostic Component
Stencil.js
Building entire design systems or large libraries of components.
Compiles to optimized vanilla JS, feature-rich, great performance.
More complex setup than Lit, more "framework-like".
Application Architecture
Micro-Frontends with Module Federation
Building a large-scale application where different teams use different frameworks for different features.
Ultimate flexibility, team autonomy, independent deployments.
High complexity, requires significant architectural planning.
Final Recommendation
For creating a single "SPA page" that can be dropped into a React, Vue, or Angular application, your best bet is to build it as a Web Component using Lit.
It provides the perfect balance of simplicity, power, and future-proof compatibility because it relies on native browser standards.