Installation
Prerequisites
- Node.js >= 16
- uni-app project (based on Vue 3)
- pnpm / npm / yarn
Install Dependencies
pnpm add @meng-xi/uni-routernpm install @meng-xi/uni-routeryarn add @meng-xi/uni-routerPeer Dependencies
@meng-xi/uni-router declares vue as an optional peer dependency. If your project already has Vue 3 installed, no additional steps are needed. If not, ensure Vue 3 is in your project:
{
"dependencies": {
"vue": "^3.0.0"
}
}TIP
vue is marked as optional because the core routing logic doesn't depend on the Vue runtime. You only need Vue's inject feature when using the useRouter() / useRoute() composables.
TypeScript Support
@meng-xi/uni-router is written in TypeScript with built-in type definitions. No additional @types packages are needed.
Ensure your tsconfig.json includes:
{
"compilerOptions": {
"moduleResolution": "bundler",
"types": ["@dcloudio/types"]
}
}INFO
@dcloudio/types provides type declarations for uni-app global APIs. Install it via pnpm add -D @dcloudio/types if not already present.
Verify Installation
Create a router instance and check if it works:
import { createRouter } from '@meng-xi/uni-router'
const router = createRouter({
routes: [
{ path: 'pages/index/index', name: 'home' }
]
})
console.log(router.currentRoute.path)If the console outputs / (the initial route path), the installation is successful.
