1

Hello I have a problem that I solved yesterday but it appears again.

I try to use a function for routing between my vue pages.

routes.js

import Page from '../components/Page'

const routes = {
    Page
}

export const vue = routes

Navigator.js

import { topmost } from 'tns-core-modules/ui/frame'

function navigateTo (page) {
  topmost().currentPage.__vuePageRef__.$navigateTo(page)
}

export { navigateTo }

Vue Page:

import {navigateTo} from "../router/navigator";

  created: function() {
    navigateTo(routes.vue.Page);
  }

but it throws me the error

System.err: TypeError: Cannot read property 'currentPage' of undefined

I remember that I have solved the problem yesterday by changing the navigateTo 'function' to a 'default function'.

But this time it throws me an error called:

System.err: TypeError: Object(...) is not a function

when im passing the routes.vue.Page

I would appreciate any help thanks.

1 Answer 1

1

It doesn't precisely fix the errors you get, but has worked fine yet.

router.js

import login from "./views/Login";
import home from "./views/Home";

export default {
    login,
    home
}

main.js

import Vue from "nativescript-vue";
import router from "./router";

Vue.prototype.$goTo = function(to, props, params) {
    if (!router[to]) return;

    this.$navigateTo(router[to], {
        props,
        ...params // clearHistory, backstackVisible
    });
}

Component.vue

export default {
    methods: {
        goToLogin() {
            this.$goTo("login");
        },
        goToHome(prop) {
            this.$goTo("home", { prop }, { clearHistory: true });
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.