
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
@esmx/router-vue
Advanced tools
Vue integration for @esmx/router - A universal router that works seamlessly with both Vue 2.7+ and Vue 3
Vue integration for @esmx/router - A universal router that works seamlessly with both Vue 2.7+ and Vue 3.
English | 中文
✨ Universal Vue Support - Works with both Vue 2.7+ and Vue 3
🎯 Composition API First - Built for modern Vue development
🔗 Seamless Integration - Drop-in replacement for Vue Router
🚀 TypeScript Ready - Full TypeScript support with excellent DX
⚡ High Performance - Optimized for production use
🔄 SSR Compatible - Server-side rendering support
npm install @esmx/router @esmx/router-vue
import { createApp, h } from 'vue';
import { Router, RouterMode } from '@esmx/router';
import { RouterPlugin, useProvideRouter } from '@esmx/router-vue';
import App from './App.vue';
const routes = [
{ path: '/', component: () => import('./views/Home.vue') },
{ path: '/about', component: () => import('./views/About.vue') }
];
const router = new Router({
routes,
mode: RouterMode.history
});
const app = createApp({
setup() {
useProvideRouter(router);
return {};
},
render: () => h(App)
});
// Install the plugin
app.use(RouterPlugin);
app.mount('#app');
import Vue from 'vue';
import { Router, RouterMode } from '@esmx/router';
import { RouterPlugin, useProvideRouter } from '@esmx/router-vue';
import App from './App.vue';
const routes = [
{ path: '/', component: () => import('./views/Home.vue') },
{ path: '/about', component: () => import('./views/About.vue') }
];
const router = new Router({
routes,
mode: RouterMode.history
});
// Install the plugin
Vue.use(RouterPlugin);
new Vue({
setup() {
useProvideRouter(router);
},
render: h => h(App)
}).$mount('#app');
<template>
<div id="app">
<nav>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/about">About</RouterLink>
<RouterLink to="/users/123">User Profile</RouterLink>
</nav>
<!-- Route components will be rendered here -->
<RouterView />
</div>
</template>
<script setup lang="ts">
import { useRouter, useRoute } from '@esmx/router-vue';
import { watch } from 'vue';
const router = useRouter();
const route = useRoute();
// Programmatic navigation
const goToAbout = () => {
router.push('/about');
};
const goBack = () => {
router.back();
};
// Watch route changes
watch(() => route.path, (newPath) => {
// Handle route change logic here
});
</script>
<template>
<div>
<h1>{{ route.meta?.title || 'Page' }}</h1>
<p>Current path: {{ route.path }}</p>
<p>Route params: {{ JSON.stringify(route.params) }}</p>
<p>Query params: {{ JSON.stringify(route.query) }}</p>
<button @click="goToAbout">Go to About Page</button>
<button @click="goBack">Go Back</button>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { getRouter, getRoute } from '@esmx/router-vue';
export default defineComponent({
mounted() {
const router = getRouter(this);
const route = getRoute(this);
// Access current route information
},
methods: {
navigate() {
const router = getRouter(this);
router.push('/dashboard');
}
}
});
</script>
A component for creating navigation links.
Props:
Prop | Type | Default | Description |
---|---|---|---|
to | string | RouteLocationInput | - | Target route location |
type | RouterLinkType | 'push' | Navigation type ('push' | 'replace' | 'pushWindow' | 'replaceWindow' | 'pushLayer' ) |
exact | RouteMatchType | 'include' | Active state matching ('include' | 'exact' | 'route' ) |
activeClass | string | - | CSS class for active state |
event | string | string[] | 'click' | Events that trigger navigation |
tag | string | 'a' | HTML tag to render |
layerOptions | RouterLayerOptions | - | Layer navigation options (used with type="pushLayer" ) |
Usage:
<template>
<!-- Basic link -->
<RouterLink to="/home">Home</RouterLink>
<!-- Replace navigation -->
<RouterLink to="/login" type="replace">Login</RouterLink>
<!-- Custom styling -->
<RouterLink
to="/dashboard"
active-class="nav-active"
exact="exact"
>
Dashboard
</RouterLink>
<!-- Custom tag -->
<RouterLink to="/submit" tag="button" class="btn">
Submit
</RouterLink>
</template>
A component that renders the matched route component.
Usage:
<template>
<div>
<!-- Root level routes render here -->
<RouterView />
<!-- Nested routes will render in child RouterView components -->
<!-- Each RouterView automatically handles the correct depth -->
</div>
</template>
Get the router instance for navigation.
function useRouter(): Router
Usage:
<script setup>
import { useRouter } from '@esmx/router-vue';
const router = useRouter();
const navigate = () => {
router.push('/about');
};
</script>
Get the current route information (reactive).
function useRoute(): Route
Usage:
<script setup>
import { useRoute } from '@esmx/router-vue';
const route = useRoute();
// Access route properties
// route.path - Current path
// route.params - Route parameters
// route.query - Query parameters
// route.meta - Route metadata
</script>
Provide router context to child components.
function useProvideRouter(router: Router): void
Usage:
import { Router, RouterMode } from '@esmx/router';
import { useProvideRouter } from '@esmx/router-vue';
const router = new Router({
routes,
mode: RouterMode.history
});
// In your app's setup function
setup() {
useProvideRouter(router);
}
Create reactive link helpers for custom navigation components.
function useLink(props: RouterLinkProps): ComputedRef<RouterLinkResolved>
Usage:
<script setup>
import { useLink } from '@esmx/router-vue';
const link = useLink({
to: '/home',
type: 'push',
exact: 'include'
}).value;
</script>
<template>
<a
v-bind="link.attributes"
v-on="link.getEventHandlers()"
:class="{ active: link.isActive }"
>
Custom Link
</a>
</template>
Get router instance in Options API components.
function getRouter(instance: VueInstance): Router
Get current route in Options API components.
function getRoute(instance: VueInstance): Route
Vue plugin that registers RouterLink and RouterView components globally.
const RouterPlugin = {
install(app: App): void
}
Usage:
// Vue 3
app.use(RouterPlugin);
// Vue 2
Vue.use(RouterPlugin);
This package provides full TypeScript support for both Vue 2.7+ and Vue 3. For Options API usage, the package automatically augments Vue component instances with $router
and $route
properties, allowing you to access them directly in templates and component methods.
// Options API type augmentation (automatic)
declare module 'vue/types/vue' {
interface Vue {
readonly $router: Router;
readonly $route: Route;
}
}
Options API Usage:
<template>
<div>
<!-- Direct access without 'this.' -->
<p>Current path: {{ $route.path }}</p>
<button @click="navigate">Navigate to About Page</button>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
methods: {
navigate() {
// TypeScript knows about $router and $route
this.$router.push('/about');
// Access current route: this.$route.path
}
}
});
</script>
<script setup lang="ts">
import { useLink } from '@esmx/router-vue';
import type { RouterLinkProps } from '@esmx/router';
interface Props extends RouterLinkProps {
icon?: string;
disabled?: boolean;
}
const props = defineProps<Props>();
const link = useLink(props).value;
</script>
<template>
<button
v-bind="link.attributes"
v-on="link.getEventHandlers()"
:class="{
active: link.isActive,
disabled: disabled
}"
:disabled="disabled"
>
<i v-if="icon" :class="icon" />
<slot />
</button>
</template>
<script setup>
import { useRouter, useRoute } from '@esmx/router-vue';
import { onMounted, onBeforeUnmount } from 'vue';
const router = useRouter();
const route = useRoute();
onMounted(() => {
// Add route guard
const unregister = router.beforeEach((to, from) => {
// Check if route requires authentication (isAuthenticated is your auth function)
if (to.meta?.requiresAuth && !isAuthenticated()) {
return '/login';
}
});
// Cleanup on unmount
onBeforeUnmount(unregister);
});
</script>
new Router()
constructor from @esmx/router
useProvideRouter()
instead of router installationRouterPlugin
for global componentsBefore (Vue Router):
import { createRouter, createWebHistory } from 'vue-router';
const router = createRouter({
history: createWebHistory(),
routes
});
app.use(router);
After (@esmx/router-vue):
import { Router, RouterMode } from '@esmx/router';
import { RouterPlugin, useProvideRouter } from '@esmx/router-vue';
import { createApp, h } from 'vue';
import App from './App.vue';
const router = new Router({
routes,
mode: RouterMode.history
});
const app = createApp({
setup() {
useProvideRouter(router);
return {};
},
render: () => h(App)
});
app.use(RouterPlugin);
import
/export
) and dynamic imports (import()
)We welcome contributions! Please feel free to submit issues and pull requests.
MIT © Esmx Team
FAQs
Vue integration for @esmx/router - A universal router that works seamlessly with both Vue 2.7+ and Vue 3
The npm package @esmx/router-vue receives a total of 330 weekly downloads. As such, @esmx/router-vue popularity was classified as not popular.
We found that @esmx/router-vue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.