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

Fix adding duplicated routes when users were using router.extendRoutes #1281

Draft
wants to merge 2 commits into
base: v7
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/helpers/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function makeRoutes (baseRoutes, {
const localizedRoute = { ...route }

// Make localized route name. Name might not exist on parent route if child has same path.
if (name) {
if (name && !name.includes(routesNameSeparator)) {
localizedRoute.name = name + routesNameSeparator + locale
}

Expand Down Expand Up @@ -142,6 +142,8 @@ export function makeRoutes (baseRoutes, {
!isChildWithRelativePath &&
// Skip default locale if strategy is PREFIX_EXCEPT_DEFAULT
!(isDefaultLocale && strategy === STRATEGIES.PREFIX_EXCEPT_DEFAULT)
// Route name already comes with prefix
&& (name && !name.includes(routesNameSeparator))
)

if (shouldAddPrefix) {
Expand All @@ -163,7 +165,11 @@ export function makeRoutes (baseRoutes, {

localizedRoute.path = path

routes.push(localizedRoute)
const matchingRoute = routes.find(({ name }) => name === localizedRoute.name)

if (!matchingRoute || matchingRoute.children) {
routes.push(localizedRoute)
}
}

return routes
Expand Down