router
router copied to clipboard
Option to remove the trailing slash
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
Posible solution?
{
path: '(.*)/',
action: (context, commands) => {
return commands.redirect(context.pathname.slice(0, -1));
}
},
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.
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. 😕