Skip to content

Instantly share code, notes, and snippets.

@Strahinja
Last active November 10, 2019 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Strahinja/95b36c27afd7719aab26efad343d6534 to your computer and use it in GitHub Desktop.
Save Strahinja/95b36c27afd7719aab26efad343d6534 to your computer and use it in GitHub Desktop.
Dynamic routes in a Nuxt.js SSR project
<!--pages/search/_docid.vue-->
<template>
<div class="search">
<nuxt-link to="/">Back to home</nuxt-link>
<p>{{docBodies[documentId]}}</p>
</div>
<!--doc-->
</template>
<script>
export default {
name: "Search",
asyncData({ params }) {
return {
documentId: params.docid,
docBodies: {
first: "First document",
second: "Second document"
}
};
}
};
</script>
<!-- ... -->
<!--pages/index.vue-->
<template>
<section>
<nuxt-link to="/search/first">Search: "first"</nuxt-link>
<nuxt-link to="/search/second">Search: "second"</nuxt-link>
</section>
</template>
<script>
export default {
name: "Index"
};
</script>
<!-- ... -->
export default {
/*
** Rendering mode
** Doc: https://nuxtjs.org/api/configuration-mode
*/
mode: "universal",
// ...
generate: {
// ***************************************************
// *** Without the next line, F5 on dynamic routes ***
// *** will fail ***
// ***************************************************
fallback: true
},
// ...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment