preact-router
Advanced tools
Comparing version 2.5.2 to 2.5.3
@@ -0,3 +1,8 @@ | ||
import * as preact from 'preact'; | ||
export function route(url: string, replace?: boolean): boolean; | ||
export function route(options: { url: string; replace?: boolean }): boolean; | ||
export function getCurrentUrl(): string; | ||
export interface CustomHistory { | ||
@@ -11,5 +16,9 @@ getCurrentLocation?: () => string; | ||
export interface RouterProps extends JSX.HTMLAttributes, preact.ComponentProps { | ||
export interface RoutableProps { | ||
path?: string; | ||
default?: boolean; | ||
} | ||
export interface RouterProps extends RoutableProps { | ||
history?: CustomHistory; | ||
path?: string; | ||
static?: boolean; | ||
@@ -21,3 +30,7 @@ url?: string; | ||
canRoute(url: string): boolean; | ||
getMatchingChildren(children: preact.VNode[], url: string, invoke: boolean): preact.VNode[]; | ||
getMatchingChildren( | ||
children: preact.VNode[], | ||
url: string, | ||
invoke: boolean | ||
): preact.VNode[]; | ||
routeTo(url: string): boolean; | ||
@@ -27,19 +40,12 @@ render(props: RouterProps, {}): preact.VNode; | ||
export interface RouteArgs<PropsType, StateType> { | ||
component: preact.Component<PropsType, StateType>; | ||
path: string; | ||
matches?: boolean; | ||
url?: string; | ||
export interface RouteProps<C> extends RoutableProps { | ||
component: preact.AnyComponent<C, any>; | ||
} | ||
export function Route<PropsType, StateType>({component, url, matches}: RouteArgs<PropsType, StateType>): preact.VNode; | ||
export function Route<C>( | ||
props: RouteProps<C> & { [P in keyof C]: C[P] } | ||
): preact.VNode; | ||
export function Link(props: any): preact.VNode; | ||
export function Link(props: JSX.HTMLAttributes): preact.VNode; | ||
export namespace Router { | ||
var route: ((url: string, replace?: boolean) => boolean); | ||
var Route: (({component, url, matches}) => preact.VNode); | ||
var Link: ((props: any) => preact.VNode); | ||
} | ||
export default Router; |
{ | ||
"name": "preact-router", | ||
"amdName": "preactRouter", | ||
"version": "2.5.2", | ||
"version": "2.5.3", | ||
"description": "Connect your components up to that address bar.", | ||
@@ -28,3 +28,3 @@ "main": "dist/preact-router.js", | ||
], | ||
"x-typings": "./dist/index.d.ts", | ||
"typings": "./dist/index.d.ts", | ||
"keywords": [ | ||
@@ -31,0 +31,0 @@ "preact", |
@@ -30,3 +30,4 @@ # preact-router | ||
<About path="/about" /> | ||
<Search path="/search/:query" /> | ||
// Advanced is an optional query | ||
<Search path="/search/:query/:advanced?" /> | ||
</Router> | ||
@@ -47,2 +48,3 @@ ); | ||
You can even mix-and-match URL parameters and normal `props`. | ||
You can also make params optional by adding a `?` to it. | ||
@@ -54,2 +56,3 @@ ```js | ||
<C path="/c/:id" /> | ||
<C path="/d/:optional?/:params?" /> | ||
<D default /> | ||
@@ -69,7 +72,7 @@ </Router> | ||
path="/friends" | ||
component={ () => import('./friends') } | ||
component={ () => import('./friends').then(module => module.default) } | ||
/> | ||
<AsyncRoute | ||
path="/friends/:id" | ||
component={ () => import('./friend') } | ||
component={ () => import('./friend').then(module => module.default) } | ||
loading={ () => <div>loading...</div> } | ||
@@ -139,2 +142,30 @@ /> | ||
### Redirects | ||
Can easily be impleted with a custom `Redirect` component; | ||
```js | ||
import { Component } from 'preact'; | ||
import { route } from 'preact-router'; | ||
export default class Redirect extends Component { | ||
componentWillMount() { | ||
route(this.props.to); | ||
} | ||
render() { | ||
return null; | ||
} | ||
} | ||
``` | ||
Now to create a redirect within your application, you can add this `Redirect` component to your router; | ||
```js | ||
<Router> | ||
<Bar path="/bar" /> | ||
<Redirect path="/foo" to="/bar" /> | ||
</Router> | ||
``` | ||
--- | ||
@@ -141,0 +172,0 @@ |
@@ -0,3 +1,8 @@ | ||
import * as preact from 'preact'; | ||
export function route(url: string, replace?: boolean): boolean; | ||
export function route(options: { url: string; replace?: boolean }): boolean; | ||
export function getCurrentUrl(): string; | ||
export interface CustomHistory { | ||
@@ -11,5 +16,9 @@ getCurrentLocation?: () => string; | ||
export interface RouterProps extends JSX.HTMLAttributes, preact.ComponentProps { | ||
export interface RoutableProps { | ||
path?: string; | ||
default?: boolean; | ||
} | ||
export interface RouterProps extends RoutableProps { | ||
history?: CustomHistory; | ||
path?: string; | ||
static?: boolean; | ||
@@ -21,3 +30,7 @@ url?: string; | ||
canRoute(url: string): boolean; | ||
getMatchingChildren(children: preact.VNode[], url: string, invoke: boolean): preact.VNode[]; | ||
getMatchingChildren( | ||
children: preact.VNode[], | ||
url: string, | ||
invoke: boolean | ||
): preact.VNode[]; | ||
routeTo(url: string): boolean; | ||
@@ -27,19 +40,12 @@ render(props: RouterProps, {}): preact.VNode; | ||
export interface RouteArgs<PropsType, StateType> { | ||
component: preact.Component<PropsType, StateType>; | ||
path: string; | ||
matches?: boolean; | ||
url?: string; | ||
export interface RouteProps<C> extends RoutableProps { | ||
component: preact.AnyComponent<C, any>; | ||
} | ||
export function Route<PropsType, StateType>({component, url, matches}: RouteArgs<PropsType, StateType>): preact.VNode; | ||
export function Route<C>( | ||
props: RouteProps<C> & { [P in keyof C]: C[P] } | ||
): preact.VNode; | ||
export function Link(props: any): preact.VNode; | ||
export function Link(props: JSX.HTMLAttributes): preact.VNode; | ||
export namespace Router { | ||
var route: ((url: string, replace?: boolean) => boolean); | ||
var Route: (({component, url, matches}) => preact.VNode); | ||
var Link: ((props: any) => preact.VNode); | ||
} | ||
export default Router; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36405
748
176