router icon indicating copy to clipboard operation
router copied to clipboard

Option to remove the trailing slash

Open abdonrd opened this issue 5 years ago • 3 comments

I would like to have the option to remove the trailing slash, to avoid the SEO duplicate content issue.

When a user go to: myapp.com/user/abdonrd/ Redirects to: myapp.com/user/abdonrd

abdonrd avatar Feb 16 '19 12:02 abdonrd

Posible solution?

{
  path: '(.*)/',
  action: (context, commands) => {
    return commands.redirect(context.pathname.slice(0, -1));
  }
},

abdonrd avatar Feb 16 '19 18:02 abdonrd

A problem with this solution (https://github.com/vaadin/vaadin-router/issues/323#issuecomment-464368131) is that we are deleting the possible URL search params.

abdonrd avatar Aug 15 '19 09:08 abdonrd

I just tried with this:

// Redirect to URL without trailing slash
{
  path: '(.*)/',
  action: (context, commands) => {
    const newPath = context.pathname.slice(0, -1) + context.search;
    return commands.redirect(newPath);
  }
},

But seems that commands.redirect() does not respect the search. 😕

abdonrd avatar Oct 23 '19 10:10 abdonrd