generated from hemengke1997/ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4d2f66
commit 9f159a1
Showing
13 changed files
with
31 additions
and
49 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
import { type AgnosticRouteObject, matchRoutes } from '@remix-run/router' | ||
import { routes } from 'virtual:remix-flat-routes' | ||
import { matchRoutes } from '@remix-run/router' | ||
import { i18nOptions } from './i18n' | ||
|
||
export async function resolveNamespace(pathname = window.location.pathname) { | ||
const res = await Promise.all( | ||
matchRoutes(routes as AgnosticRouteObject[], pathname)?.map(async (route) => { | ||
const { handle } = route.route | ||
if (typeof handle === 'function') { | ||
return await handle() | ||
} | ||
return handle | ||
export async function resolveNamespace(pathname: string = window.location.pathname) { | ||
const res = await Promise.all<string[]>( | ||
matchRoutes(window.__remixRouter.routes, pathname)?.map(async (_route) => { | ||
const { route } = _route | ||
await route.lazy?.() | ||
return new Promise<string[]>((resolve) => { | ||
function r(): string[] { | ||
if (typeof route?.handle !== 'object') return [] | ||
if (!route.handle) return [] | ||
if (!('i18n' in route.handle)) return [] | ||
if (typeof route.handle.i18n === 'string') return [route.handle.i18n] | ||
if (Array.isArray(route.handle.i18n) && route.handle.i18n.every((value) => typeof value === 'string')) { | ||
return route.handle.i18n as string[] | ||
} | ||
return [] | ||
} | ||
setTimeout(() => { | ||
resolve(r()) | ||
}) | ||
}) | ||
}) || [], | ||
) | ||
|
||
return res | ||
.filter((t) => t?.i18n) | ||
.map((t) => t.i18n) | ||
.flat() | ||
.concat(i18nOptions.defaultNS) | ||
return res.flatMap((t) => t).concat(i18nOptions.defaultNS) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.