Skip to content

Commit

Permalink
Rename RouterHistory to RouterHistoryOption
Browse files Browse the repository at this point in the history
  • Loading branch information
kyarik committed Dec 21, 2020
1 parent 920d281 commit a4445f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const router = createRouter([
interface RouterOptions {
defaultFallback?: ComponentType;
errorFallback?: ComponentType<{ error: Error; retry: () => void }>;
history?: RouterHistory;
history?: RouterHistoryOption;
onError?: (error: Error, errorInfo: ErrorInfo) => void;
preloadOnLinkHover?: PreloadContentOption;
preloadOnLinkPressIn?: PreloadContentOption;
Expand All @@ -217,7 +217,7 @@ interface RouterOptions {

- `errorFallback?: ComponentType<{ error: Error; retry: () => void }>` is the error fallback component to show when an error occurs for some route, e.g., when the component or data for a route fails to load. This component is given two props: `error` and `retry`. `error` is the `Error` object and `retry` is a callback to retry loading the failed route. Generally, you should include a _Retry_ button in the error fallback, and pass `retry` as its `onClick` prop.

- `history?: RouterHistory` (default: `'browser'`) specifies the type of history object to use for route navigation. The history object is created with the [`history` package](https://github.com/ReactTraining/history). `RouterHistory` can be one of the following:
- `history?: RouterHistoryOption` (default: `'browser'`) specifies the type of history object to use for route navigation. The history object is created with the [`history` package](https://github.com/ReactTraining/history). `RouterHistoryOption` can be one of the following:

- `'browser'` creates a `BrowserHistory` that uses the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API). The current route's path will be the actual path in the URL. For example, if the domain is `https://example.com` and the route path is `/profile`, then the URL for the page will be `https://example.com/profile`.
- `'hash'` creates a `HashHistory`. The current route's path will be in the hash portion of the URL. For example, if the domain is `https://example.com`, the path under which the page loads is `/`, and the route path is `/profile`, then the URL for the page will be `https://example.com/#/profile`.
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export type UseTransition = () => [(callback: () => void) => void, boolean];

export type PreloadContentOption = 'code' | 'code-and-data' | 'none';

export type RouterHistory = 'browser' | 'hash' | 'memory' | ['memory', MemoryHistoryOptions];
export type RouterHistoryOption = 'browser' | 'hash' | 'memory' | ['memory', MemoryHistoryOptions];

export interface RouterOptions {
defaultFallback?: ComponentType;
errorFallback?: ComponentType<{ error: Error; retry: () => void }>;
history?: RouterHistory;
history?: RouterHistoryOption;
onError?: (error: Error, errorInfo: ErrorInfo) => void;
preloadOnLinkHover?: PreloadContentOption;
preloadOnLinkPressIn?: PreloadContentOption;
Expand Down
16 changes: 8 additions & 8 deletions src/utils/createHistory/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { assertNever } from 'circumspect';
import { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
import { RouterHistory } from '../../types';
import { RouterHistoryOption } from '../../types';

export const createHistory = (routerHistory: RouterHistory) => {
if (routerHistory === 'browser') {
export const createHistory = (routerHistoryOption: RouterHistoryOption) => {
if (routerHistoryOption === 'browser') {
return createBrowserHistory();
}

if (routerHistory === 'memory') {
if (routerHistoryOption === 'memory') {
return createMemoryHistory();
}

if (routerHistory === 'hash') {
if (routerHistoryOption === 'hash') {
return createHashHistory();
}

if (Array.isArray(routerHistory)) {
return createMemoryHistory(routerHistory[1]);
if (Array.isArray(routerHistoryOption)) {
return createMemoryHistory(routerHistoryOption[1]);
}

return assertNever(routerHistory);
return assertNever(routerHistoryOption);
};

0 comments on commit a4445f6

Please sign in to comment.