I have two view components.
The first component, productList.vue,
renders the list of products. Each listed product routes you to the product info(second view).
seeTheProduct(product) {
this.$router.push({
name: 'productinfo',
params: { data: product }
})
}
function's parameter product
is an object with name
, color
, URL
, etc. fields.
In the second view, productInfo.vue
, I get the data in created
hook and render it.
created() {
this.product = this.$route.params.data;
console.log('the local product is ', this.product)
}
it works fine until I do a normal reload of the product info page, I lose the passed product
parameter data.
I tried all solutions online but still couldn't solve my problem. I was thinking about localStorage but it seems it's not that persistent, or again retrieve data from the server, but might be an expensive operation. Is there any other solution?
EDIT:
router.js:
const routes = [
{
path: "/",
name: "Home",
component: Home,
},
{
path: "/admin",
name: "admin",
component: Admin,
meta: { requiresAuth: true },
children: [
{
path: "overview",
name: "overview",
component: Overview,
},
{
path: "products",
name: "products",
component: Products,
},
{
path: "profile",
name: "profile",
component: Profile,
},
{
path: "orders",
name: "orders",
component: Orders,
},
],
},
{
path: "/adminlogin",
name: AdminLogin,
component: () =>
import(/* webpackChunkName: "about" */ "../views/AdminLogin.vue"),
},
{
path: "/about",
name: "About",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ "../views/About.vue"),
},
{
path: "/checkout",
name: "checkout",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ "../views/Checkout.vue"),
},
{
path: "/productinfo",
name: "productinfo",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ "../views/ProductInfo.vue"),
},
];
const router = new VueRouter({
mode: "history",
routes,
});