mirror of
https://github.com/outline/outline.git
synced 2026-12-01 17:32:49 +03:00
Standardize route templates as match constants in routeHelpers
All route matcher templates now live alongside the existing match* constants in routeHelpers, so the route map, route definitions, and scene-internal routes consume one consistent set of constants instead of a mix of path functions, template literals, and hardcoded strings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W45zR5AhPpLURRoDQUsAgX
This commit is contained in:
5 files changed
+83
-52
No files matched your search
@@ -15,10 +15,10 @@ import useQueryNotices from "~/hooks/useQueryNotices";
|
||||
import {
|
||||
homePath,
|
||||
settingsPath,
|
||||
matchDocumentSlug as documentSlug,
|
||||
matchCollectionSlug as collectionSlug,
|
||||
matchCollectionNew,
|
||||
matchDocumentEdit,
|
||||
matchDocumentHistory,
|
||||
matchDocumentShortlink,
|
||||
} from "~/utils/routeHelpers";
|
||||
import env from "~/env";
|
||||
import { routeMap } from "./map";
|
||||
@@ -86,11 +86,7 @@ function AuthenticatedRoutes() {
|
||||
<Redirect exact from="/starred" to={homePath()} />
|
||||
<Redirect exact from="/templates" to={settingsPath("templates")} />
|
||||
<Redirect exact from="/collections/*" to="/collection/*" />
|
||||
<Route
|
||||
exact
|
||||
path={`/collection/${collectionSlug}/new`}
|
||||
component={DocumentNew}
|
||||
/>
|
||||
<Route exact path={matchCollectionNew} component={DocumentNew} />
|
||||
<Route
|
||||
exact
|
||||
path={routeMap.collection.paths}
|
||||
@@ -99,7 +95,7 @@ function AuthenticatedRoutes() {
|
||||
<Route exact path="/doc/new" component={DocumentNew} />
|
||||
<Route
|
||||
exact
|
||||
path={`/d/${documentSlug}`}
|
||||
path={matchDocumentShortlink}
|
||||
component={RedirectDocument}
|
||||
/>
|
||||
<Route
|
||||
|
||||
+13
-16
@@ -6,7 +6,12 @@ import FullscreenLoading from "~/components/FullscreenLoading";
|
||||
import Route from "~/components/ProfiledRoute";
|
||||
import env from "~/env";
|
||||
import lazy from "~/utils/lazyWithRetry";
|
||||
import { matchDocumentSlug as documentSlug } from "~/utils/routeHelpers";
|
||||
import {
|
||||
matchDocument,
|
||||
matchDocumentSlug as documentSlug,
|
||||
matchShare,
|
||||
matchShareDocument,
|
||||
} from "~/utils/routeHelpers";
|
||||
import useAutoRefresh from "~/hooks/useAutoRefresh";
|
||||
import { routeMap } from "./map";
|
||||
|
||||
@@ -31,13 +36,9 @@ export default function Routes() {
|
||||
{env.ROOT_SHARE_ID ? (
|
||||
<Switch>
|
||||
<Route exact path="/" component={Shared} />
|
||||
<Route exact path={`/doc/${documentSlug}`} component={Shared} />
|
||||
<Redirect exact from="/s/:shareId" to="/" />
|
||||
<Redirect
|
||||
exact
|
||||
from={`/s/:shareId/doc/${documentSlug}`}
|
||||
to={`/doc/${documentSlug}`}
|
||||
/>
|
||||
<Route exact path={matchDocument} component={Shared} />
|
||||
<Redirect exact from={matchShare} to="/" />
|
||||
<Redirect exact from={matchShareDocument} to={matchDocument} />
|
||||
</Switch>
|
||||
) : (
|
||||
<Switch>
|
||||
@@ -47,19 +48,15 @@ export default function Routes() {
|
||||
<Route exact path="/desktop-redirect" component={DesktopRedirect} />
|
||||
<Route exact path="/oauth/authorize" component={OAuthAuthorize} />
|
||||
|
||||
<Redirect exact from="/share/:shareId" to="/s/:shareId" />
|
||||
<Route exact path="/s/:shareId" component={Shared} />
|
||||
<Redirect exact from="/share/:shareId" to={matchShare} />
|
||||
<Route exact path={matchShare} component={Shared} />
|
||||
|
||||
<Redirect
|
||||
exact
|
||||
from={`/share/:shareId/doc/${documentSlug}`}
|
||||
to={`/s/:shareId/doc/${documentSlug}`}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path={`/s/:shareId/doc/${documentSlug}`}
|
||||
component={Shared}
|
||||
to={matchShareDocument}
|
||||
/>
|
||||
<Route exact path={matchShareDocument} component={Shared} />
|
||||
|
||||
<Authenticated>
|
||||
<AuthenticatedRoutes />
|
||||
|
||||
+22
-26
@@ -2,16 +2,18 @@
|
||||
import type * as React from "react";
|
||||
import { createLazyComponent } from "~/components/LazyLoad";
|
||||
import {
|
||||
archivePath,
|
||||
debugPath,
|
||||
draftsPath,
|
||||
homePath,
|
||||
matchArchive,
|
||||
matchChangesets,
|
||||
matchCollection,
|
||||
matchCollectionEdit,
|
||||
matchCollectionSlug,
|
||||
matchDocumentSlug,
|
||||
searchPath,
|
||||
settingsPath,
|
||||
trashPath,
|
||||
matchDebug,
|
||||
matchDocument,
|
||||
matchDrafts,
|
||||
matchHome,
|
||||
matchSearch,
|
||||
matchSettings,
|
||||
matchShare,
|
||||
matchTrash,
|
||||
} from "~/utils/routeHelpers";
|
||||
|
||||
/**
|
||||
@@ -39,29 +41,23 @@ export interface RouteMapEntry {
|
||||
* prefix with.
|
||||
*/
|
||||
export const routeMap = {
|
||||
drafts: defineRoute(draftsPath(), () => import("~/scenes/Drafts")),
|
||||
archive: defineRoute(archivePath(), () => import("~/scenes/Archive")),
|
||||
trash: defineRoute(trashPath(), () => import("~/scenes/Trash")),
|
||||
home: defineRoute(`${homePath()}/:tab?`, () => import("~/scenes/Home")),
|
||||
search: defineRoute(
|
||||
`${searchPath()}/:query?`,
|
||||
() => import("~/scenes/Search")
|
||||
),
|
||||
drafts: defineRoute(matchDrafts, () => import("~/scenes/Drafts")),
|
||||
archive: defineRoute(matchArchive, () => import("~/scenes/Archive")),
|
||||
trash: defineRoute(matchTrash, () => import("~/scenes/Trash")),
|
||||
home: defineRoute(matchHome, () => import("~/scenes/Home")),
|
||||
search: defineRoute(matchSearch, () => import("~/scenes/Search")),
|
||||
collection: defineRoute(
|
||||
[matchCollectionEdit, `/collection/${matchCollectionSlug}/:tab?`],
|
||||
[matchCollectionEdit, matchCollection],
|
||||
() => import("~/scenes/Collection")
|
||||
),
|
||||
document: defineRoute(
|
||||
`/doc/${matchDocumentSlug}`,
|
||||
() => import("~/scenes/Document")
|
||||
),
|
||||
settings: defineRoute(settingsPath(), () => import("./settings")),
|
||||
shared: defineRoute("/s/:shareId", () => import("~/scenes/Shared")),
|
||||
document: defineRoute(matchDocument, () => import("~/scenes/Document")),
|
||||
settings: defineRoute(matchSettings, () => import("./settings")),
|
||||
shared: defineRoute(matchShare, () => import("~/scenes/Shared")),
|
||||
changesets: defineRoute(
|
||||
`${debugPath()}/changesets`,
|
||||
matchChangesets,
|
||||
() => import("~/scenes/Developer/Changesets")
|
||||
),
|
||||
debug: defineRoute(debugPath(), () => import("~/scenes/Developer/Debug")),
|
||||
debug: defineRoute(matchDebug, () => import("~/scenes/Developer/Debug")),
|
||||
};
|
||||
|
||||
function defineRoute(
|
||||
|
||||
@@ -14,7 +14,7 @@ import history from "~/utils/history";
|
||||
import {
|
||||
documentPath,
|
||||
matchDocumentHistory,
|
||||
matchDocumentSlug,
|
||||
matchDocument,
|
||||
} from "~/utils/routeHelpers";
|
||||
import SidebarLayout from "~/scenes/Document/components/SidebarLayout";
|
||||
|
||||
@@ -42,7 +42,7 @@ const DocumentSidebarContent = observer(function DocumentSidebarContent({
|
||||
const isMobile = useMobile();
|
||||
|
||||
const inner = (
|
||||
<Route path={`/doc/${matchDocumentSlug}`}>
|
||||
<Route path={matchDocument}>
|
||||
<React.Suspense
|
||||
fallback={
|
||||
<SidebarLayout title={<PlaceholderText width={100} />}>
|
||||
|
||||
@@ -334,15 +334,57 @@ export function desktopify(path: string, origin?: string): string {
|
||||
export const matchCollectionSlug =
|
||||
":collectionSlug([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})";
|
||||
|
||||
/** Route matcher for the collection screen. */
|
||||
export const matchCollection = `/collection/${matchCollectionSlug}/:tab?`;
|
||||
|
||||
/** Route matcher for the collection edit screen. */
|
||||
export const matchCollectionEdit = `/collection/${matchCollectionSlug}/overview/edit`;
|
||||
|
||||
/** Route matcher for creating a new document in a collection. */
|
||||
export const matchCollectionNew = `/collection/${matchCollectionSlug}/new`;
|
||||
|
||||
/** Route matcher for a document slug. */
|
||||
export const matchDocumentSlug =
|
||||
":documentSlug([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})";
|
||||
|
||||
/** Route matcher for the document screen. */
|
||||
export const matchDocument = `/doc/${matchDocumentSlug}`;
|
||||
|
||||
/** Route matcher for the document edit screen. */
|
||||
export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`;
|
||||
|
||||
/** Route matcher for the document history screen. */
|
||||
export const matchDocumentHistory = `/doc/${matchDocumentSlug}/history/:revisionId?`;
|
||||
|
||||
/** Route matcher for the document shortlink redirect screen. */
|
||||
export const matchDocumentShortlink = `/d/${matchDocumentSlug}`;
|
||||
|
||||
/** Route matcher for the home screen. */
|
||||
export const matchHome = "/home/:tab?";
|
||||
|
||||
/** Route matcher for the drafts screen. */
|
||||
export const matchDrafts = "/drafts";
|
||||
|
||||
/** Route matcher for the archive screen. */
|
||||
export const matchArchive = "/archive";
|
||||
|
||||
/** Route matcher for the trash screen. */
|
||||
export const matchTrash = "/trash";
|
||||
|
||||
/** Route matcher for the search screen. */
|
||||
export const matchSearch = "/search/:query?";
|
||||
|
||||
/** Route matcher for the settings screens. */
|
||||
export const matchSettings = "/settings";
|
||||
|
||||
/** Route matcher for the debug screen. */
|
||||
export const matchDebug = "/debug";
|
||||
|
||||
/** Route matcher for the changesets debug screen. */
|
||||
export const matchChangesets = `${matchDebug}/changesets`;
|
||||
|
||||
/** Route matcher for a publicly shared collection or document. */
|
||||
export const matchShare = "/s/:shareId";
|
||||
|
||||
/** Route matcher for a document within a public share. */
|
||||
export const matchShareDocument = `${matchShare}/doc/${matchDocumentSlug}`;
|
||||
Reference in new issue
Block a user