Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple router implementation that is suitable for NativeScript-Vue.

NotificationsYou must be signed in to change notification settings

emiliogrv/nativescript-vue-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Prerequisites / Requirements

All your own components must have unique name
All routes name must have unique name
Your app need a main Frame in the render

Install

npm install nativescript-vue-router-ns --saveoryarn add nativescript-vue-router-ns

Usage

// 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>

Guards and other before actions

// 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()}})// ...

API

Installing

ParametersTypeDefaultDescription
ignoreSameBooleantrueSet if reject or accept navigate to same current component.
routesArray[]Array of objects with app's routes.
verboseBooleanfalseShow output the warnings to console.

Navigating

This package provides 3 methods for navigation,$router.push,$router.pushClear and$router.back

ParametersTypeDescription
nameStringFirst parameter inpush andpushClear methods.
optionsObjectIs 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.

TODO

  • Native navigation
  • Before actions
  • After actions
  • Nested routes

Contributing

Thank you for considering contributing to the NSVueRouter! Please leave your PR orissue.

License

MIT

About

A simple router implementation that is suitable for NativeScript-Vue.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp