{"id":15141907,"url":"https://github.com/mattccc/nativescript-vue-router-extended","last_synced_at":"2025-10-23T18:30:58.049Z","repository":{"id":57308820,"uuid":"399272686","full_name":"MattCCC/nativescript-vue-router-extended","owner":"MattCCC","description":"A simple Router for NativeScript-Vue, built on top of $navigateTo so to simplify routing between the pages","archived":false,"fork":false,"pushed_at":"2022-11-11T23:29:27.000Z","size":257,"stargazers_count":20,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T20:30:04.005Z","etag":null,"topics":["nativescript","nativescript-vue","router","vue"],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/nativescript-vue-router-extended","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MattCCC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"mattccc","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-08-23T23:14:40.000Z","updated_at":"2024-05-30T16:03:39.000Z","dependencies_parsed_at":"2023-01-22T00:16:29.236Z","dependency_job_id":null,"html_url":"https://github.com/MattCCC/nativescript-vue-router-extended","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattCCC%2Fnativescript-vue-router-extended","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattCCC%2Fnativescript-vue-router-extended/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattCCC%2Fnativescript-vue-router-extended/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattCCC%2Fnativescript-vue-router-extended/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MattCCC","download_url":"https://codeload.github.com/MattCCC/nativescript-vue-router-extended/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237869284,"owners_count":19379295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nativescript","nativescript-vue","router","vue"],"created_at":"2024-09-26T09:20:24.428Z","updated_at":"2025-10-23T18:30:52.664Z","avatar_url":"https://github.com/MattCCC.png","language":"TypeScript","funding_links":["https://patreon.com/mattccc"],"categories":[],"sub_categories":[],"readme":"# NativeScript Vue Router\n\n[npm-url]: https://npmjs.org/package/nativescript-vue-router-extended\n[npm-image]: http://img.shields.io/npm/v/nativescript-vue-router-extended.svg\n\n[![NPM version][npm-image]][npm-url] [![Blazing Fast](https://badgen.now.sh/badge/speed/blazing%20%F0%9F%94%A5/green)](https://github.com/MattCCC/nativescript-vue-router-extended) [![Code Coverage](https://badgen.now.sh/badge/coverage/0.00/blue)](https://github.com/MattCCC/nativescript-vue-router-extended) [![npm downloads](https://img.shields.io/npm/dm/nativescript-vue-router-extended.svg?style=flat-square)](http://npm-stat.com/charts.html?package=nativescript-vue-router-extended) [![install size](https://packagephobia.now.sh/badge?p=nativescript-vue-router-extended)](https://packagephobia.now.sh/result?p=nativescript-vue-router-extended)\n\n[nativescript-vue-router-extended](https://github.com/mattCCC/nativescript-vue-router-extended)\n\nNativeScript Vue Router brings easier routing handling to mobile apps, with an API compatibility with web version of Vue Router.\n\nPlease file an issue or make a PR if you spot any problems or you have any further requests regarding the functionality.\n\n## Table of Contents\n\n- [Features](#features)\n- [Prerequisites / Requirements](#prerequisites-requirements)\n- [Installation](#installation)\n- [Usage \u0026 Examples](#usage-examples)\n- [New hooks for pages](#new-hooks-for-pages)\n- [TypeScript](#typescript)\n- [API Differences to Web](#api-differences-to-web)\n- [Troubleshooting](#troubleshooting)\n\n## Features\n\n- Same hooks and guards for mobile and web\n- Additional action dispatcher to dispatch actions to store automatically when changing routes\n- Vue-Router 4 API compatibility\n- NativeScript-Vue compatible\n- TypeScript Support out of the box\n\n## Prerequisites / Requirements\n\nNativescript 7.1+ is required for the plugin to run properly. It might be working on previous NS6 although the plugin is no longer officially supported for NativeScript 6.\n\n## Installation\n\n```javascript\nns plugin add nativescript-vue-router-extended\n\nor\n\nnpm install nativescript-vue-router-extended\n\nor\n\nyarn add nativescript-vue-router-extended\n```\n\n[![NPM](https://nodei.co/npm/nativescript-vue-router-extended.png)](https://npmjs.org/package/nativescript-vue-router-extended)\n\n## Usage \u0026 Examples\n\nTo use this plugin you need to import it and initialize the router using `createRouter()` function. Global and per component Vue-Router hooks and guards are supported.\n\n```javascript\nimport Vue from \"nativescript-vue\";\nimport { createRouter } from \"nativescript-vue-router-extended\";\n\n// Initialize Example Routes\nimport moviesPage from \"./pages/movies.vue\";\n\nconst routes = [\n  {\n    path: \"/movies\",\n    component: moviesPage,\n\n    // Optional\n    meta: {\n      isVertical: true,\n      // Example actions to dispatch automatically when page is visited\n      // Remember that you need to implement actions in your Vuex store\n      store: {\n        // Call action to hide navigation buttons\n        showNavigationButtons: false,\n\n        // Call \"showMovies\" action in \"categories\" module with payload \"all\"\n        \"categories/showMovies\": \"all\",\n\n        // Call action without payload\n        showNavigationButtons: null,\n      },\n    },\n\n    // Optional, per route guards are supported\n    // More info: https://next.router.vuejs.org/guide/advanced/navigation-guards.html#per-route-guard\n    beforeEnter: (to, from) =\u003e {\n      if (to.props.passUser) {\n         // Continue navigation\n         return true;\n      }\n\n      // Reject the navigation\n      return false;\n    },\n  },\n];\n\n// Initialize Router\n// Vue-Router settings are in 1st argument. 2nd one is used for extra NativeScript related settings\nconst router = createRouter(\n  { routes },\n  {\n    // Optional settings below\n\n    // Set first page to redirect to when there's no page to redirect back to\n    routeBackFallbackPath: \"/movies\",\n\n    // Do something straight before navigation or adjust NS routing settings\n    routeToCallback: (to, options) =\u003e {\n      // For example, change page navigation transition for the vertical on iOS\n      if (to.meta.isVertical) {\n        options.transition = {\n          name: \"fade\",\n        };\n      }\n    },\n\n    // Do something straight before navigation or adjust NS routing settings\n    routeBackCallback: (_to, options) =\u003e {\n      // Do something...\n    },\n\n    // Set Vue Instance (Vue.prototype by default)\n    vm: Vue.prototype,\n\n    // Set a custom logger (console.log by default)\n    logger: console.log,\n\n    // Set custom frame, by default it's taken from @nativescript/core/ui/frame\n    frame: Frame,\n  }\n);\n\n// Register a global guard (optional)\n// You can also use global router.beforeResolve guard and router.afterEach hook\nrouter.beforeEach((to) =\u003e {\n  // For example, verify per route access rules\n  if (!canAccessRoute(to)) {\n    return false;\n  }\n\n  return true;\n});\n\n// From now on you can access this.$router, this.$routeBack and special this.$routeTo inside of the components, example:\nthis.$routeTo(\"/movies\", {\n  // Clear History is a NativeScript setting\n  clearHistory: true,\n  \n  // Route inside of custom Frame\n  frame: \"myFrameId\",\n\n  // Pass props to the page\n  props: {\n    movieId: 12,\n  },\n});\n```\n\n## New hooks for pages\n\nYou can use hooks directly on particular pages. It is discouraged to use them inside of mixins or components for the time being. Example below:\n\n```javascript\n\u003ctemplate\u003e\n    \u003cPage\u003e\n    \u003c/Page\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\n\nexport default {\n    name: 'movies',\n\n    beforeRouteEnter(to, from, next) {\n        // Do something before to enter to the route\n        next((vm) =\u003e {\n            // Do something once navigation is done\n            // Instead of `this`, use `vm`\n        });\n    },\n\n    beforeRouteLeave() {\n        // Do something before to leave the route\n        // You can use `this` inside of this hook\n    },\n\n    beforeRouteUpdate() {\n        // Do something before to leave the route\n        // before redirecting to another route with same path\n        // You can use `this` inside of this hook\n    },\n\n    mounted() {\n       // Output current route object with name, path etc.\n       console.log(this.$route);\n    },\n};\n\u003c/script\u003e\n```\n\n| NS Event       | Mapped as           | Description                                                                                                                                                                                                                                                                                                  |\n| -------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| navigatingFrom | `beforeRouteLeave`  | Before user leaves the route                                                                                                                                                                                                                                                                                 |\n| navigatingTo   | `beforeRouteEnter`  | Before user enters a route                                                                                                                                                                                                                                                                                   |\n| -              | `beforeRouteUpdate` | Before route is changed but view remains the same. This can happen when path is exactly the same but you change e.g. passed prop to the route. Please refer to Vue-Router docs for more details.                                                                                                             |\n| navigatedTo    | `beforeRouteEnter`  | To trigger it properly you need to access component instance. You can use `next(vm =\u003e ...)` callback within `beforeRouteEnter()`. Please check Vue-Router docs for more details.                                                                                                                             |\n| navigatedFrom  | -                   | This event is tricky to control for developers. There is no exact mapping of it in the router. For store state cleanup use build-in meta dispatcher instead. For component state you could opt for using `beforeRouteLeave()`. |\n\n## TypeScript Support\nIf you need a TS support and it's not detected automatically in your project for some reason, you can use [typings/shims.vue.d.ts](https://github.com/MattCCC/nativescript-vue-router-extended/blob/master/src/typings/shims-vue.d.ts) to bring proper support in .vue files. You can specify it in your `shims.vue.d.ts` file (attention! Please ensure that path is relative to your node_modules directory):\n```\n/// \u003creference path=\"./node_modules/nativescript-vue-router-extended/typings/shims-vue.d.ts\" /\u003e\n```\n\n## API Differences to Web\n\n\u003cb\u003eVue Router compatibility\u003c/b\u003e\n\nThis plugin aims for compatibility with Vue Router 3+ and Vue Router 4+. Both should be easily supported. Please refer to [Vue Router Docs](https://next.router.vuejs.org/guide/) for more information.\n\n\u003cb\u003eDOM \u0026 related hooks\u003c/b\u003e\n\nThere are some limitations like lack of DOM accessibility and related hooks and guards.\n\n\u003cb\u003eRouterLink Component\u003c/b\u003e\n\nThere's a lack of \u003crouter-link /\u003e component due to performance reasons.\n\n\u003cb\u003ePassing props to pages\u003c/b\u003e\n\nAll props are passed automatically to \u003cPage /\u003e components. Therefore you don't need to use `props: true` in your routes list.\n\n\u003cb\u003eMeta Dispatcher\u003c/b\u003e\n\nAn additional option that allows you to dispatch actions to Vuex store directly from routes list using `meta.store` object. To utilize it you may need to define `Vue.prototype.$store = store;` after to register your Vue store.\n\n\n## License\n\nApache License Version 2.0, January 2004\n\n## Troubleshooting\n\nPlease file an issue. You can use the template but it is not required. Just simply write what is your issue so we can try to reproduce and fix it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattccc%2Fnativescript-vue-router-extended","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattccc%2Fnativescript-vue-router-extended","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattccc%2Fnativescript-vue-router-extended/lists"}