- Notifications
You must be signed in to change notification settings - Fork1
emiliogrv/nativescript-vue-router
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
All your own components must have unique name |
All routes name must have unique name |
Your app need a main Frame in the render |
npm install nativescript-vue-router-ns --saveoryarn add nativescript-vue-router-ns
// app/router/index.jsimportVuefrom'nativescript-vue'importNSVueRouterfrom'nativescript-vue-router-ns'importDashboardfrom'./components/Dashboard'importLoginfrom'./components/Login'Vue.use(NSVueRouter)constroutes=[{name:'dashboard.index',component:Dashboard,meta:{auth:true}},{name:'login.index',component:Login,meta:{guest:true}}]constrouter=newNSVueRouter({ ignoreSame,// <-- Optional. Will set if reject or accept navigate to same current component. routes,/* eslint-disable-next-line no-undef */verbose:TNS_ENV!=='production'// <-- Optional. Will output the warnings to console.})exportdefaultrouter
// app/app.js or app/main.jsimportVuefrom'nativescript-vue'importMainfrom'./Main'importrouterfrom'./router'newVue({router// ...render:h=>h('frame',[h(Main)])// <-- Main Frame in render app}).$start()
<!-- Your own Vue Components --><template><PageactionBarHidden="true"><FlexboxLayoutflexDirection="column"justifyContent="center"><buttontext="Navigate direct"@tap="$router.push('dashboard.index')"/><buttontext="Navigate with method"@tap="submit"/></FlexboxLayout></Page></template><script>exportdefault{name:'LoginIndex',methods:{submit(){// ...this.$router.pushClear('dashboard.index')// ...}}}</script>
// app/router/index.js// ...router.beforeEach((to,next)=>{if(to.meta.auth&&isLogged){/* eslint-disable-next-line no-undef */if(TNS_ENV!=='production'){/* eslint-disable-next-line no-console */console.error(newError('To Login!.'))}router.pushClear('login.index')}elseif(to.meta.guest&&isLogged){router.push('dashboard.index')}else{next()}})// ...
Parameters | Type | Default | Description |
---|---|---|---|
ignoreSame | Boolean | true | Set if reject or accept navigate to same current component. |
routes | Array | [] | Array of objects with app's routes. |
verbose | Boolean | false | Show output the warnings to console. |
This package provides 3 methods for navigation,$router.push
,$router.pushClear
and$router.back
Parameters | Type | Description |
---|---|---|
name | String | First parameter inpush andpushClear methods. |
options | Object | Is an optional object, which accepts all options supported byManual Routing |
times | [String, Number] | Optional parameter inback method that go back any times that you set. |
NOTE: When$router.pushClear
method is used the navigator stack is cleaned.
- Native navigation
- Before actions
- After actions
- Nested routes
Thank you for considering contributing to the NSVueRouter! Please leave your PR orissue.
About
A simple router implementation that is suitable for NativeScript-Vue.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.