Nuxt.js - force trailing slash at the end of all urls

后端 未结 2 1939
遥遥无期
遥遥无期 2021-01-21 07:04

I\'m looking for a way to make sure that all of my urls end with a trailing slash (so first check if there is already a trailing slash at the end, and if not add one).

I

相关标签:
2条回答
  • 2021-01-21 07:22

    The following regex handles query string as well:

    redirect: [
        {
            from: '^(\\/[^\\?]*[^\\/])(\\?.*)?$',
            to: '$1/$2',
        },
    ],
    
    0 讨论(0)
  • 2021-01-21 07:24

    You can try to match only those URLs that do not end with a slash:

    redirect: [
        {
            from: '^.*(?<!\/)$',
            to: (from, req) => req.url + '/'
        }
    ]
    
    0 讨论(0)
提交回复
热议问题