Context failed to pass in dynamic route
See original GitHub issueDescription
Having used Gridsome from version 0.5, I’m relatively new to the newly introduced dynamic routing in version 0.7.5
I have created an empty file /customer/[:id].vue
and use an API that GET all customer information and pass the context
to each route by using dynamic route /customer/:id
.
However, when I click into individual customer page, for example, /customer/1
and /customer/2
, both context.name
remain the same value. context.name
is called in the customer template.
I haven’t implemented any rewrite rule as I’m not entirely sure where and how I should apply it based on my use case. The documentation is pretty limited too.
Any help? Am I using dynamic route the correct way?
// gridsome.server.js
api.createManagedPages(async ({ createPage }) => {
const agent = new https.Agent({
rejectUnauthorized: false
});
const { data } = await axios.get(
"https://api.mycompany.com/Customer/GetAll",
{ httpsAgent: agent }
);
data.forEach(item => {
console.log(item.customer_id)
console.log(item.name)
console.log(item.alias)
createPage({
path: `/customer/:id(\\d+)`,
component: "./src/templates/Customer.vue",
context: {
id: item.customer_id,
name: item.name,
alias: item.alias
}
});
});
});
// /templates/Customer.vue
<template>
<Layout>
<div class="main-content">
<div class="header">
<div class="container-fluid">
<!-- Body -->
<div class="header-body">
<div class="row align-items-center">
<div class="col-auto">
<!-- Avatar -->
<a href="#!" class="avatar avatar-lg">
<span class="avatar-title rounded bg-white text-warning">
<span class="fe fe-user"></span>
</span>
</a>
</div>
<div class="col ml-n3 ml-md-n2">
<!-- Pretitle -->
<h6 class="header-pretitle">Customer</h6>
<!-- Title -->
<h1 class="header-title">{{ $context.name }}</h1>
</div>
</div>
<!-- <SingleCustomerTopNavbar /> -->
<div class="row align-items-center">
<div class="col">
<ul class="nav nav-tabs nav-overflow header-tabs">
<li
class="nav-item"
v-for="tab in tabs"
v-bind:key="tab"
v-on:click="currentTab = tab"
>
<a
href="#"
class="nav-link"
v-bind:class="['tab-button', { active: currentTab === tab }]"
>{{ tab }}</a>
</li>
</ul>
</div>
</div>
<!-- end nav bar -->
</div>
</div>
</div>
<component v-bind:is="currentTabComponent" v-bind:customer_name="$context.name" v-bind:customer_id="$context.id"></component>
</div>
</Layout>
</template>
<script>
import Layout from "~/layouts/Default.vue";
import SingleCustomerTopNavbar from "~/components/navbar/SingleCustomerTopNavbar.vue";
import Overview from "~/components/customer/Overview.vue";
import News from "~/components/customer/News.vue";
import Products from "~/components/customer/Products.vue";
import Visits from "~/components/customer/Visits.vue";
export default {
data() {
return {
currentTab: "Overview",
tabs: ["Overview", "News", "Products", "Visits", "Share"]
};
},
computed: {
currentTabComponent: function() {
return this.currentTab;
}
},
components: {
Layout,
SingleCustomerTopNavbar,
Overview,
News,
Products,
Visits
}
};
</script>
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
My next.js code for dynamic content and routing isn't ...
I'm trying to create a dynamic content and routing for my website with the codes below but there is an error: import Link...
Read more >Router tutorial: tour of heroes
Define an array of routes, appRoutes , and pass them to the RouterModule. ... The application fails if the user clicks that button...
Read more >How to use getStaticPaths on dynamic routes in Next.js
You will learn how to make use of Next.js getStaticPaths & getStaticProps on a dynamic route to create a Master-Detail UI commonly used...
Read more >Shallow Routing
This is due to middleware being able to rewrite dynamically and can't be verified client-side without a data fetch which is skipped with...
Read more >Troubleshooting Router Error Responses
For more information, see Dynamic Routing Table in the Gorouter ... ContextCancelled, 499, No, Client/App, Logs with error context canceled
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@hjvedvik When is this going to be officially in the docs?
I am having the same issue, though it also doesn’t even work when I create explicit pages:
when querying
allPage
I do see the correct context, but it is never sent to the template, eg.$context
is{}