Get router push parameters

Hi, I am trying to navigate a new page and get some parameters through router push, unfortunately, I got the below error, please advise,

<script>
import router from '../routes'
export default {
  data () {
    return {
      createdOn:''
    }
  },
  created(){
     this.getParams()
  },
  methods: {
      getParams () {
        console.log(router.params);
        var routerParams = router.params
        this.createdOn = routerParams.createdOn
        console.log(routerParams);
      }
  }
}
</script>

I’m not exactly clear what’s in the file ../routes but it seems unlikely to be what you want. You seem to be using it as a way to get hold of the current route.

More likely you want to try this.$route (see https://router.vuejs.org/api/#component-injections), perhaps this.$route.params.createdOn?

Usually it’s better not to grab the route at all inside components and to let the router inject those parameters as props instead. See https://router.vuejs.org/guide/essentials/passing-props.html.

Here is the router code, I triggered the router.push in vuex, and I didn’t register the router in the main.js

import Vue from 'vue'
import VueRouter from 'vue-router'
//import store from './Stores/account.module'
import Signin from './Login/Signin.vue'
import Home from './Home/Home.vue'
import Reg from './Register/Registration.vue'
import Mem from './Members/MemberDetails.vue'

Vue.use(VueRouter);

const routes = [
    //{path:'/home',name:'home',component:Home},
    {path:'/mem',name:'mem',component:Mem},
    {path:'/login',name:'login',component:Signin},
    {path:'/reg',name:'reg',component:Reg},
    {
        path: '/home',
        component: Home,
        beforeEnter (to, from, next) {
          const publicPages = ['/login', '/reg'];
          const authRequired = !publicPages.includes(to.path);
          const loggedIn = localStorage.getItem('userId');
        
          if (authRequired && !loggedIn) {
            return next('/login');
          }
        
          next();
        }
      } 
]

export default new VueRouter({mode: 'history', routes})

So your routes file is exporting the router instance. You can get the current route using router.currentRoute, see https://router.vuejs.org/api/#router-currentroute.

You haven’t explained why you aren’t adding the router to your root Vue instance. That would be my preferred option so you can access the route using this.$route.