question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

url match strict for seo

See original GitHub issue

Environment

  • Operating System: Darwin
  • Node Version: v16.11.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: app, router, css, typescript, modules, components, vueuse, unocss
  • Runtime Modules: @vueuse/nuxt@8.5.0, @unocss/nuxt@0.33.5, @pinia/nuxt@0.1.9
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-ty2wyb?file=nuxt.config.ts,app.vue

Describe the bug

I used nuxt.config

router: {
    options: {
      strict:true
    }
  }

console error No match found for location with path "/art/a178/"

my pages tree

pages
├── art
   ├── a[id]
       └── index.vue
   |──b[id].vue

I think “/art/a178/” should match the index.vue ,and “/art/b17” match the b[id].vue. This is good for seo

Sorry for my poor English. Is the description clear.

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
danielroecommented, Jul 4, 2022

Setting strict doesn’t default router to using trailing slashes - it only makes the router care about it: https://router.vuejs.org/api/#strict.

If you want to force trailing slashes, you will need to use pages:extend to modify the paths generated by Nuxt to include a trailing slash. See an example implementation at https://stackblitz.com/edit/github-ty2wyb-8cl4ib.

1reaction
YuLoguncommented, Aug 16, 2022

Daniel, thanks for an example.

Perhaps, you could also suggest what should be done in my case: My problem is that I do need slashes at the end of every path, but I don’t want to show a 404 error if the user navigates to a path without a slash. I want to redirect the user to a path with slashes in that case.

As I understand, redirect-module is not compatible with Nuxt 3.

What is the solution to implement redirect from a page without a slash to a page with it?


My current approach: I removed withTrailingSlash and router option from nuxt.config and tried to use it in Nuxt route middleware (middleware/redirect.global.ts).

export default defineNuxtRouteMiddleware((to) => {
  if (!to.path.endsWith('/') && to.path !== '/') {
    return navigateTo(withTrailingSlash(to.fullPath, true), {
      redirectCode: 301,
    });
  }
});

Is it the way to do it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

URL Best Practices For SEO
Match the URLs to the titles​​ Human searchers can better picture what your site offers by matching your URL to your page titles....
Read more >
URL Structure: Best Practices for SEO-Friendly URLs
1. Follow a good URL structure · 2. Use HTTPS protocol · 3. Hide the www prefix · 4. Edit the page URL...
Read more >
Do Exact Match Domains Still Work Anymore?
Exact match domains (EMDs) precisely match a search query that will likely drive traffic to your website, and historically tended to rank well....
Read more >
15 SEO Best Practices for Structuring URLs - Moz
#3: Keywords in URLs: still a good thing​​ It's important that your keyword research is well-informed, especially if they're used in your URL....
Read more >
URLs for SEO: How to create SEO-friendly links
Creating consistency between what your URL reads and your page title can boost your rankings in search engines. One way to do that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found