Router companion for Nativescript-Vue 2.0's Manual Routing.
Yep, that's her, Nami from One Piece. Why? Coz she's a navigator.
npm
npm install ns-vue-nami
yarn
yarn add ns-vue-nami
Create a router
folder with an index.js
file within your app
folder.
app
|- components
|- router
|- index.js
index.js
import Vue from 'nativescript-vue';
import NsVueNami from 'ns-vue-nami';
import login from '~/components/login';
import dashboard from '~/components/dashboard';
import isAuthenticated from 'some-authentication-module';
Vue.use(NsVueNami);
const vm = new Vue();
vm.$nami.authGuard((next) => {
if(isAuthenticated) {
next();
} else {
next('login');
}
});
// register all routes here.
vm.$nami.init({
routes: [
{
name: 'login',
component: login,
noAuth: true,
entry: !isAuthenticated
},
{
name: 'dashboard',
component: dashboard,
entry: isAuthenticated
}
]
});
main.js
Just invoke the router in your main.js
.
import '@babel/polyfill';
import entry from './router';
new Vue({
store,
render: h => h('frame', [h(entry)])
}).$start();
Please note the import of the babel/polyfill
above, this might be necessary to avoid this bug:NativeScript encountered a fatal error: ReferenceError: Can't find variable: regeneratorRuntime
you can install the polyfill by running npm install --save-dev @babel/polyfill
and importing it as seen above.
From the template
<button @tap="$nami.navigate('foo')">Go to foo</button>
From script
export default {
methods: {
someFunc() {
this.$nami.navigate('bar');
}
}
}
.init()
Sets all the routable components across the whole app.Returns the entry component to be used in main.js as frame entry.
Router properties:
name: String
- The component name of your choice.component: Vue component
- The vue component.noAuth: Boolean: default - false
- The component will NOT require authentication if set to true.entry: Boolean
- Set a particular component as entry point.import login from '~/components/login';
import dashboard from '~/components/dashboard';
vm.$nami.init({
routes: [
{
name: 'login',
component: login,
entry: true
},
{
name: 'dashboard',
component: dashboard
}
]
})
.authGuard()
Will decide whether the component is routable or not based on authentication status.
import Vue from 'nativescript-vue';
import NsVueNami from '../plugins/ns-vue-nami';
import login from '~/components/login';
import dashboard from '~/components/dashboard';
// Dummy authentication status.
const isAuthenticated = true;
Vue.use(NsVueNami);
const vm = new Vue();
vm.$nami.authGuard((next) => {
if(isAuthenticated) {
next();
} else {
next('login');
}
});
export default vm.$nami.init({
routes: [
{
name: 'login',
component: login,
noAuth: true,
entry: !isAuthenticated // login will be the entry if isAuthenticated is false
},
{
name: 'dashboard',
component: dashboard,
entry: isAuthenticated // dashboard will be the entry if isAuthenticated is true
}
]
});
.register()
Adds a new route to the list of routes on the fly.
import cat from '~/components/cat';
vm.$nami.register({name: 'cat', component: cat});
.navigate()
// Basic
this.$nami.navigate('cat-component');
// With props
this.$nami.navigate('cat-component', {name: 'Kidlat', color: 'Black'});
<button @tap="$nami.navigate('cat-component', {name: 'Kidlat', color: 'Black'})">View Cat</button>
.modal()
Just like
.navigate()
but shows the component on a modal.
// Basic
this.$nami.modal('cat-component');
// With props
this.$nami.modal('cat-component', {name: 'Kidlat', color: 'Black'});
<button @tap="$nami.modal('cat-component', {name: 'Kidlat', color: 'Black'})">View Cat in a Modal</button>
.back()
Goes back to the previous component.
this.$nami.back();
<button @tap="$nami.back()">Go back</button>
NS Vue Apollo A native application built with NativeScript-Vue Usage # Install dependenciesnpm install# Build for productionnpm run buildnpm run build:<platform># Build, watch for changes and debug th
Ns-Vue-Radio is a native white-label application built with NativeScript-Vue for community radios Download and Install Download the command line tools from the android website. Follow this steps: Nati
Groceries Vue Groceries Vue is an app for managing grocery lists. Groceries Vue is also a clone of sample-Groceriesbuilt with nativescript-vue. Itshowcases the potential of the NativeScript platform u
NativeScript-Vue Application A native sample application using nativescript vue-cli template and camera pluginusing the 0.2.0 branch of the cli pluginneeded to import the ui/image module like this if
NativeScript-Vue Application Using Tabs & Login Screen A native application built with NativeScript-Vue Scaffolding for tab application with authentication Usage # Install dependenciesnpm install# Bui
这用于创建新的命名空间并将其与正在运行的程序相关联。 语法 (Syntax) 以下是语法。 (ns namespace-name) Parameters - 'namespace-name'是需要与正在运行的程序关联的命名空间。 Return Value - 无。 例子 (Example) 以下是Clojure中ns的示例。 (ns clojure.myown (:require [clo