You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
743 B

  1. <template>
  2. <div>
  3. <h1>Continent: {{ continent }}</h1>
  4. <h2>Mountain: {{ mountain }}</h2>
  5. <p>Path: {{ $route.path }}</p>
  6. <NuxtLink to="/">
  7. Back to Mountains
  8. </NuxtLink>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. async asyncData ({ params, redirect }) {
  14. const mountains = await fetch(
  15. 'https://api.nuxtjs.dev/mountains'
  16. ).then(res => res.json())
  17. const filteredMountain = mountains.find(
  18. el =>
  19. el.continent.toLowerCase() === params.continent &&
  20. el.slug === params.mountain
  21. )
  22. if (filteredMountain) {
  23. return {
  24. continent: filteredMountain.continent,
  25. mountain: filteredMountain.title
  26. }
  27. } else {
  28. redirect('/')
  29. }
  30. }
  31. }
  32. </script>