1.1.0 â€ĸ Published 2 years ago

@intlify/vue-router-bridge v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@intlify/vue-router-bridge

Vue Router bridging for Vue 2 & Vue 3

This library is inspired by vue-demi

🌟 Features

  • Vue Router composable APIs available on Vue 2 & Vue 3
    • useRouter
    • useRoute
  • Auto detect Vue Router version on bundling
  • Manual switch versions

đŸ’ŋ Installation

# npm
npm install @intlify/vue-router-bridge

# yarn
yarn add @intlify/vue-router-bridge

# pnpm
pnpm add @intlify/vue-router-bridge

â›“ī¸ Dependencies

You need to add vue-router and @vue/composition-api to your plugin's peer dependencies to specify what versions you support.

{
  "dependencies": {
    "@intlify/vue-router-bridge": "latest"
  },
  "peerDependencies": {
    "@vue/composition-api": "^1.0.0-rc.1",
    "vue-router": "^3.0.0" // or "^4.0.0" base on your preferred working environment
  },
  "peerDependenciesMeta": {
    "@vue/composition-api": {
      "optional": true
    }
  },
  "devDependencies": {
    "vue-router": "^3.0.0" // or "^4.0.0" base on your preferred working environment
  },
}

Import everything related to Vue Router from it, it will redirect to vue-router@3 + @vue/composition-api or vue-router@4 based on users' environments.

import { useRouter, useRoute } from '@intlify/vue-router-bridge'

When using with Vite, you will need to opt-out the pre-bundling to get @intlify/vue-router-bridge work properly by

// vite.config.js
export default defineConfig({
  optimizeDeps: {
    exclude: ['@intlify/vue-router-bridge']
 }
})

🤝 Extra APIs

@intlify/vue-router-bridge provides extra APIs to help distinguish users' environments and to do some version-specific logic.

isVueRouter3 / isVueRouter4

import { isVueRouter3, isVueRouter4 } from '@intlify/vue-router-bridge'

if (isVueRouter3) {
  // Vue Router 3 only
} else {
  // Vue Router 4 only
}

đŸ“ē CLI

To explicitly switch the redirecting version, you can use these commands in your project's root:

🤏 Manually Switch Versions

npx vue-router-switch 2
# or
npx vue-router-switch 3

đŸ“Ļ Package Aliasing

If you would like to import vue-router under an alias, you can use the following command:

npx vue-router-switch 2 vue2
# or
npx vue-router-switch 3 vue3

🩹 Auto Fix

If the postinstall hook doesn't get triggered or you have updated the Vue Router version, try to run the following command to resolve the redirecting:

npx vue-router-fix

âœŗī¸ Isomorphic Testings

You can support testing for both versions by adding npm alias in your dev dependencies. For example:

{
  "scripts": {
    "test:3": "vue-router-switch 2 vue-router3 && jest",
    "test:4": "vue-router-switch 3 && jest",
  },
  "devDependencies": {
    "vue-router": "^4.0.0",
    "vue-router3": "npm:vue-router@3"
  },
}

or

{
  "scripts": {
    "test:3": "vue-router-switch 4 && jest",
    "test:4": "vue-router-switch 4 vue-router4 && jest",
  },
  "devDependencies": {
    "vue-router": "^3.0.0",
    "vue-router4": "npm:vue-router@43"
  },
}

💖 Thanks

This package idea was inspired from vue-demi, @antfus great work!

ÂŠī¸ License

MIT

1.1.0-3963e97

2 years ago

1.1.0

2 years ago

1.0.1-176f3bf

2 years ago

1.0.1

2 years ago

1.0.0-bd038bf

2 years ago

1.0.0

2 years ago

0.9.0-b16ba33

2 years ago

0.9.0-cbdf4a7

2 years ago

1.0.1-4ebbaa5

2 years ago

1.0.0-ad7f3ab

2 years ago

0.9.0

2 years ago

1.0.1-ae091ea

2 years ago

1.0.1-82ef441

2 years ago

0.8.0-5a09400

2 years ago

0.8.0-a1de31a

2 years ago

0.8.0-52cef4f

3 years ago

0.8.0

3 years ago

0.5.0-feabcbc

3 years ago

0.5.0-1f3154f

3 years ago

0.5.0-f554f2c

3 years ago

0.4.0-721f0bf

3 years ago

0.6.0-633ea7c

3 years ago

0.5.0

3 years ago

0.7.0

3 years ago

0.4.0-493702c

3 years ago

0.5.0-146f2af

3 years ago

0.5.0-d15430d

3 years ago

0.6.0-a10b678

3 years ago

0.5.0-ffa56f7

3 years ago

0.4.0-ae3a113

3 years ago

0.4.0-61d9c94

3 years ago

0.5.0-c99f131

3 years ago

0.5.0-61cfb1e

3 years ago

0.7.0-27135c9

3 years ago

0.5.0-9d2d407

3 years ago

0.6.0

3 years ago

0.3.6-f4147ac

3 years ago

0.3.6-d051d25

3 years ago

0.3.6-d975fae

3 years ago

0.4.0-9c7e708

3 years ago

0.4.0-9c83915

3 years ago

0.3.6-a59042c

3 years ago

0.3.6-bfbc6a3

3 years ago

0.3.6-87b8aa7

3 years ago

0.3.6-834ec8f

3 years ago

0.4.0

3 years ago

0.3.6-6a56e52

3 years ago

0.3.5-4eac811

3 years ago

0.3.5-d430dff

3 years ago

0.3.6

3 years ago

0.3.5-96eeb2f

3 years ago

0.3.5

3 years ago

0.3.4-9cc468d

3 years ago

0.3.4-4b1e09e

3 years ago

0.3.4-d70e71d

3 years ago

0.3.4-036517b

3 years ago

0.3.4

3 years ago

0.3.4-ac88640

3 years ago

0.3.3-2eacc10

3 years ago

0.3.3-1ecc7b2

3 years ago

0.3.2-d69c466

3 years ago

0.3.3

3 years ago

0.3.2-921cb79

3 years ago

0.3.2

3 years ago

0.3.1-2f8831f

3 years ago

0.3.1-ec9532a

3 years ago

0.3.1-9a573af

3 years ago

0.3.0-1c66b25

3 years ago

0.3.1

3 years ago

0.3.0-4d9b421

3 years ago

0.3.0

3 years ago

0.2.0-174270a

3 years ago

0.2.0-c9b0866

3 years ago

0.2.0-ceed2db

3 years ago

0.2.0

3 years ago

0.1.0-c375c7d

3 years ago

0.1.0-3c0c98e

3 years ago

0.1.0-e73ac70

3 years ago

0.1.0-79dead2

3 years ago

0.1.0-63b1fb5

3 years ago

0.1.0-2e90b5a

3 years ago

0.1.0-0cf3395

3 years ago

0.1.0

3 years ago

0.0.0-6d22796

3 years ago

0.0.0-05397a9

3 years ago

0.0.0-6c9d585

3 years ago

0.0.0-18527c9

3 years ago

0.0.0-99e2c9c

3 years ago