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

allow specifying redirect in definePageMeta #14075

Closed
nivv opened this issue May 31, 2022 · 3 comments · Fixed by nuxt/framework#7746
Closed

allow specifying redirect in definePageMeta #14075

nivv opened this issue May 31, 2022 · 3 comments · Fixed by nuxt/framework#7746

Comments

@nivv
Copy link

nivv commented May 31, 2022

Environment

Nuxt CLI v3.0.0-rc.3 09:39:40
RootDir: /Users/albin/code/nuxt3-boilerplate 09:39:41
Nuxt project info: 09:39:41


  • Operating System: Darwin
  • Node Version: v16.14.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: yarn@1.22.17
  • Builder: vite
  • User Config: build
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Use router via pages folder

Describe the bug

There is currently no way to redirect one page to another when using wildcard slugs (that is documented)

image

I would like to specify it via the router options:

router.options.ts

import type { RouterConfig } from '@nuxt/schema'

// https://router.vuejs.org/api/#routeroptions
export default <RouterConfig>{
    routes: [
        {
            path: 'redirect-me',
            redirect: 'im-redirected'
        }
    ]
}

But the docs for the router says "Note: history and routes options will be always overridden by Nuxt.".

This seems like a basic enough feature. Also, would be great if the pages directory could be optional. I like defining the routes myself.

Additional context

No response

Logs

No response

@danielroe
Copy link
Member

You can currently take full control with the pages:extend hook:

export default defineNuxtConfig({
  hooks: {
    'pages:extend' (pages) {
       // decorate routes or replace them with your own routes
     }
  }
})

@danielroe danielroe changed the title No way to specify redirects allow specifying redirect in definePageMeta Jun 1, 2022
@nivv
Copy link
Author

nivv commented Jun 1, 2022

You can currently take full control with the pages:extend hook:

export default defineNuxtConfig({
  hooks: {
    'pages:extend' (pages) {
       // decorate routes or replace them with your own routes
     }
  }
})

Thanks! I'll try that!

@TheDutchCoder
Copy link
Contributor

Just to add: I too would like to see this option!
The hooks work, but it feels a bit disjointed to specify this in the config, rather than in the related page. 👍

@danielroe danielroe self-assigned this Sep 22, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants