All Projects → emiliogrv → nativescript-vue-router

emiliogrv / nativescript-vue-router

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nativescript-vue-router

nativescript-vue-multi-drawer
A NativeScript-Vue component for creating multiple side drawers (4 sides supported)
Stars: ✭ 45 (+221.43%)
Mutual labels:  nativescript, nativescript-vue
Router Module
Nuxt.js module to use router.js instead of pages/ directory.
Stars: ✭ 322 (+2200%)
Mutual labels:  router, vue-router
Nativescript Vue
Native mobile applications using Vue and NativeScript.
Stars: ✭ 4,784 (+34071.43%)
Mutual labels:  nativescript, nativescript-vue
Vue Routisan
Elegant, fluent route definitions for Vue Router, inspired by Laravel. v3 is currently in beta. [email protected]
Stars: ✭ 193 (+1278.57%)
Mutual labels:  router, vue-router
Vue Smart Route
Smart route search to make intelligent looking apps with Vue.js.
Stars: ✭ 280 (+1900%)
Mutual labels:  router, vue-router
nativescript-vue-examples
🍈 NativeScript and Vue code samples.
Stars: ✭ 13 (-7.14%)
Mutual labels:  nativescript, nativescript-vue
Router
The Hoa\Router library.
Stars: ✭ 29 (+107.14%)
Mutual labels:  router
vue-douban
高仿豆瓣app
Stars: ✭ 22 (+57.14%)
Mutual labels:  vue-router
huobi-PC
火币桌面客户端,基于electorn-vue开发
Stars: ✭ 56 (+300%)
Mutual labels:  vue-router
retil
The React Utility Library
Stars: ✭ 46 (+228.57%)
Mutual labels:  router
nativescript-performance-monitor
⚡ Proof your app maintains 60-ish FPS by collecting data or showing it on screen with this NativeScript plugin!
Stars: ✭ 21 (+50%)
Mutual labels:  nativescript
blog-frontend
前后端分离实践----基于Vue2.js框架博客前端
Stars: ✭ 32 (+128.57%)
Mutual labels:  vue-router
nativescript-calendar
📅 NativeScript plugin to Create, Delete and Find Events in the native Calendar
Stars: ✭ 44 (+214.29%)
Mutual labels:  nativescript
nativescript-http
The best way to do HTTP requests in NativeScript, a drop-in replacement for the core HTTP with important improvements and additions like proper connection pooling, form data support and certificate pinning
Stars: ✭ 32 (+128.57%)
Mutual labels:  nativescript
spirit-router
fast router for spirit
Stars: ✭ 28 (+100%)
Mutual labels:  router
OpenBSDFirewall
Simple OpenBSD Home Firewall Config for ALIX Board
Stars: ✭ 41 (+192.86%)
Mutual labels:  router
slim-wrt
Armor for Openwrt
Stars: ✭ 66 (+371.43%)
Mutual labels:  router
shim
HTTP Handler shim for Go projects running on AWS Lambda
Stars: ✭ 64 (+357.14%)
Mutual labels:  router
Vue-router
Tutorial About vue-router in Vue.js version 2
Stars: ✭ 60 (+328.57%)
Mutual labels:  vue-router
vue-for-my-english-app
this is a vue demo project for green hand
Stars: ✭ 80 (+471.43%)
Mutual labels:  vue-router

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

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 --save
or
yarn add nativescript-vue-router-ns

Usage

// app/router/index.js

import Vue from 'nativescript-vue'

import NSVueRouter from 'nativescript-vue-router-ns'

import Dashboard from './components/Dashboard'
import Login from './components/Login'

Vue.use(NSVueRouter)

const routes = [
  {
    name: 'dashboard.index',
    component: Dashboard,
    meta: { auth: true }
  },
  {
    name: 'login.index',
    component: Login,
    meta: { guest: true }
  }
]

const router = new NSVueRouter({
  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.
})

export default router
// app/app.js or app/main.js

import Vue from 'nativescript-vue'

import Main from './Main'

import router from './router'

new Vue({
  router

  // ...

  render: h => h('frame', [h(Main)]) // <-- Main Frame in render app
}).$start()
<!-- Your own Vue Components -->
<template>
  <Page actionBarHidden="true">
    <FlexboxLayout flexDirection="column" justifyContent="center">
      <button text="Navigate direct" @tap="$router.push('dashboard.index')" />

      <button text="Navigate with method" @tap="submit" />
    </FlexboxLayout>
  </Page>
</template>

<script>
  export default {
    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(new Error('To Login!.'))
    }

    router.pushClear('login.index')
  } else if (to.meta.guest && isLogged) {
    router.push('dashboard.index')
  } else {
    next()
  }
})

// ...

API

Installing

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.

Navigating

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

Parameters Type Description
name String First parameter in push and pushClear methods.
options Object Is an optional object, which accepts all options supported by Manual Routing
times [String, Number] Optional parameter in back 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 or issue.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].