Router companion for Nativescript-Vue 2.0's Manual Routing.
Yep, that's her, Nami from One Piece. Why? Coz she's a navigator.
Installation
npm
npm install ns-vue-nami
yarn
yarn add ns-vue-nami
Recommended Implementation
Create a router
folder with an index.js
file within your app
folder.
app
|- components
|- router
|- index.js
index.js
;;;;; Vue; const vm = ; vm$nami; // register all routes here.vm$nami;
main.js
Just invoke the router in your main.js
.
; store ;
Sample Usage
From the template
<button @tap="$nami.navigate('foo')">Go to foo</button>
From script
methods: { this$nami; }
API
.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.
;; vm$nami
.authGuard()
Will decide whether the component is routable or not based on authentication status.
;; ;; // Dummy authentication status.const isAuthenticated = true; Vue; const vm = ; vm$nami; $nami;
.register()
Adds a new route to the list of routes on the fly.
; vm$nami;
.navigate()
// Basicthis$nami; // With propsthis$nami;
<button @tap="$nami.navigate('cat-component', {name: 'Kidlat', color: 'Black'})">View Cat</button>
.modal()
Just like
.navigate()
but shows the component on a modal.
// Basicthis$nami; // With propsthis$nami;
<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;
<button @tap="$nami.back()">Go back</button>