Last active
November 10, 2019 14:11
-
-
Save Strahinja/95b36c27afd7719aab26efad343d6534 to your computer and use it in GitHub Desktop.
Dynamic routes in a Nuxt.js SSR project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--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> | |
<!-- ... --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--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> | |
<!-- ... --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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