Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): dynamic routes #52

Merged
merged 4 commits into from
Oct 1, 2022
Merged

feat(core): dynamic routes #52

merged 4 commits into from
Oct 1, 2022

Conversation

ojvribeiro
Copy link
Owner

@ojvribeiro ojvribeiro commented Sep 30, 2022

Resolves #49.

With dynamic routes, you can create a route wrapping the page file name in brackets:

image

Then you can access any route and get the url parameter with the @vueuse/router useRouteParams composable:

<!-- pages/[id].vue -->

<template>
  {{ userId }}
</template>

<script setup>
  import { useRouteParams } from '@vueuse/router'

  const userId = useRouteParams('id')
</script>

Will generate:

image

Then, you can use the generated userId within an API call.

⚠️ Creating a dynamic page will overwrite the "not found" behavior on its nesting level. For example, if you create a [file].vue inside the /pages/posts/ folder, there will be no 404 fallback for the route /post.

@ojvribeiro ojvribeiro added the enhancement New feature or request label Sep 30, 2022
@ojvribeiro ojvribeiro self-assigned this Sep 30, 2022
@vercel
Copy link

vercel bot commented Sep 30, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
vulmix ✅ Ready (Inspect) Visit Preview Oct 1, 2022 at 3:17AM (UTC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create dynamic file routes
1 participant