diff --git a/docs/API.md b/docs/API.md index 5f85df59b8..f38db19f84 100644 --- a/docs/API.md +++ b/docs/API.md @@ -6,7 +6,6 @@ - [``](#indexlink) - [``](#routercontext) - [`context.router`](#contextrouter) - - `` (deprecated, use ``) - [Configuration Components](#configuration-components) - [``](#route) @@ -29,12 +28,6 @@ - [`match()`](#match-routes-location-history-options--cb) - [`createRoutes()`](#createroutesroutes) - [`PropTypes`](#proptypes) - - [`useRoutes()`](#useroutescreatehistory-deprecated) (deprecated) - -- [Mixins](#mixins-deprecated) (deprecated) - - `Lifecycle` (deprecated) - - `History` (deprecated) - - `RouteContext` (deprecated) ## Components @@ -116,16 +109,7 @@ A [location descriptor](https://github.com/mjackson/history/blob/master/docs/Glo * `hash`: A hash to put in the URL, e.g. `#a-hash`. * `state`: State to persist to the `location`. -##### `query` **([Deprecated](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)** -An object of key:value pairs to be stringified. - -##### `hash` **([Deprecated](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)** -A hash to put in the URL, e.g. `#a-hash`. - -_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to the hash. Scroll position management utilities are available in the [scroll-behavior](https://github.com/taion/scroll-behavior) library._ - -##### `state` **([Deprecated](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)** -State to persist to the `location`. +_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to the hash. ##### `activeClassName` The className a `` receives when its route is active. No active class by default. @@ -581,8 +565,6 @@ class App extends React.Component { } ``` -#### `history` (deprecated) - ### Named Components When a route has one or more named components, the child elements are available by name on `this.props`. In this case `this.props.children` will be undefined. All route components can participate in the nesting. @@ -697,13 +679,3 @@ One or many [``](#route)s or [`PlainRoute`](#plainroute)s. The following prop types are exported at top level and from `react-router/lib/PropTypes`: - `routerShape`: Shape for the `router` object on context - `locationShape`: Shape for the `location` object on route component props - -Previously, a number of prop types intended for internal use were also exported under `PropTypes`. These are deprecated and should not be used. - - -### `useRoutes(createHistory)` (deprecated) - - -## Mixins (deprecated) - -Deprecated, please see the [upgrade guide](/upgrade-guides/v2.0.0.md#mixins-are-deprecated). diff --git a/modules/PropTypes.js b/modules/PropTypes.js index 5a439ad58a..001473700f 100644 --- a/modules/PropTypes.js +++ b/modules/PropTypes.js @@ -1,9 +1,5 @@ import { PropTypes } from 'react' -import deprecateObjectProperties from './deprecateObjectProperties' -import * as InternalPropTypes from './InternalPropTypes' -import warning from './routerWarning' - const { func, object, shape, string } = PropTypes export const routerShape = shape({ @@ -23,56 +19,3 @@ export const locationShape = shape({ action: string.isRequired, key: string }) - -// Deprecated stuff below: - -export let falsy = InternalPropTypes.falsy -export let history = InternalPropTypes.history -export let location = locationShape -export let component = InternalPropTypes.component -export let components = InternalPropTypes.components -export let route = InternalPropTypes.route -export let routes = InternalPropTypes.routes -export let router = routerShape - -if (__DEV__) { - const deprecatePropType = (propType, message) => (...args) => { - warning(false, message) - return propType(...args) - } - - const deprecateInternalPropType = propType => ( - deprecatePropType(propType, 'This prop type is not intended for external use, and was previously exported by mistake. These internal prop types are deprecated for external use, and will be removed in a later version.') - ) - - const deprecateRenamedPropType = (propType, name) => ( - deprecatePropType(propType, `The \`${name}\` prop type is now exported as \`${name}Shape\` to avoid name conflicts. This export is deprecated and will be removed in a later version.`) - ) - - falsy = deprecateInternalPropType(falsy) - history = deprecateInternalPropType(history) - component = deprecateInternalPropType(component) - components = deprecateInternalPropType(components) - route = deprecateInternalPropType(route) - routes = deprecateInternalPropType(routes) - - location = deprecateRenamedPropType(location, 'location') - router = deprecateRenamedPropType(router, 'router') -} - -let defaultExport = { - falsy, - history, - location, - component, - components, - route, - // For some reason, routes was never here. - router -} - -if (__DEV__) { - defaultExport = deprecateObjectProperties(defaultExport, 'The default export from `react-router/lib/PropTypes` is deprecated. Please use the named exports instead.') -} - -export default defaultExport diff --git a/modules/RoutingContext.js b/modules/RoutingContext.js deleted file mode 100644 index d6e712ce65..0000000000 --- a/modules/RoutingContext.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react' -import RouterContext from './RouterContext' -import warning from './routerWarning' - -const RoutingContext = React.createClass({ - componentWillMount() { - warning(false, '`RoutingContext` has been renamed to `RouterContext`. Please use `import { RouterContext } from \'react-router\'`. http://tiny.cc/router-routercontext') - }, - - render() { - return - } -}) - -export default RoutingContext diff --git a/modules/__tests__/_bc-serverRendering-test.js b/modules/__tests__/_bc-serverRendering-test.js deleted file mode 100644 index 0bd4ac3203..0000000000 --- a/modules/__tests__/_bc-serverRendering-test.js +++ /dev/null @@ -1,104 +0,0 @@ -import expect from 'expect' -import React, { Component } from 'react' -import { renderToString } from 'react-dom/server' - -import Link from '../Link' -import match from '../match' -import RoutingContext from '../RoutingContext' -import shouldWarn from './shouldWarn' - -describe('v1 server rendering', function () { - - class App extends Component { - render() { - return ( -
-

App

- About{' '} - Dashboard -
- {this.props.children} -
-
- ) - } - } - - class Dashboard extends Component { - render() { - return ( -
-

The Dashboard

-
- ) - } - } - - class About extends Component { - render() { - return ( -
-

About

-
- ) - } - } - - const DashboardRoute = { - path: '/dashboard', - component: Dashboard - } - - const AboutRoute = { - path: '/about', - component: About - } - - const RedirectRoute = { - path: '/company', - onEnter(nextState, replaceState) { - replaceState(null, '/about') - } - } - - const routes = { - path: '/', - component: App, - childRoutes: [ DashboardRoute, AboutRoute, RedirectRoute ] - } - - it('works', function (done) { - shouldWarn('has been renamed') - - match({ routes, location: '/dashboard' }, function (error, redirectLocation, renderProps) { - const string = renderToString( - - ) - expect(string).toMatch(/The Dashboard/) - done() - }) - }) - - it('renders active Links as active', function (done) { - shouldWarn('has been renamed') - - match({ routes, location: '/about' }, function (error, redirectLocation, renderProps) { - const string = renderToString( - - ) - expect(string).toMatch(/about-is-active/) - expect(string).toNotMatch(/dashboard-is-active/) - done() - }) - }) - - it('sends null values when no routes match', function (done) { - match({ routes, location: '/no-match' }, function (error, redirectLocation, state) { - expect(error).toNotExist() - expect(redirectLocation).toNotExist() - expect(state).toNotExist() - done() - }) - }) - -}) diff --git a/modules/__tests__/_bc-transitionHooks-test.js b/modules/__tests__/_bc-transitionHooks-test.js deleted file mode 100644 index 01fca42925..0000000000 --- a/modules/__tests__/_bc-transitionHooks-test.js +++ /dev/null @@ -1,190 +0,0 @@ -import expect, { spyOn } from 'expect' -import React, { Component } from 'react' -import { render, unmountComponentAtNode } from 'react-dom' -import createHistory from 'history/lib/createMemoryHistory' -import execSteps from './execSteps' -import Router from '../Router' -import shouldWarn from './shouldWarn' - -describe('v1 When a router enters a branch', function () { - - class Dashboard extends Component { - render() { - return ( -
-

The Dashboard

- {this.props.children} -
- ) - } - } - - class NewsFeed extends Component { - render() { - return
News
- } - } - - class Inbox extends Component { - render() { - return
Inbox
- } - } - - let node, DashboardRoute, NewsFeedRoute, InboxRoute, RedirectToInboxRoute, MessageRoute, routes - beforeEach(function () { - node = document.createElement('div') - - NewsFeedRoute = { - path: 'news', - component: NewsFeed, - onEnter(nextState, replaceState) { - expect(this).toBe(NewsFeedRoute) - expect(nextState.routes).toContain(NewsFeedRoute) - expect(replaceState).toBeA('function') - }, - onLeave() { - expect(this).toBe(NewsFeedRoute) - } - } - - InboxRoute = { - path: 'inbox', - component: Inbox, - onEnter(nextState, replaceState) { - expect(this).toBe(InboxRoute) - expect(nextState.routes).toContain(InboxRoute) - expect(replaceState).toBeA('function') - }, - onLeave() { - expect(this).toBe(InboxRoute) - } - } - - RedirectToInboxRoute = { - path: 'redirect-to-inbox', - onEnter(nextState, replaceState) { - expect(this).toBe(RedirectToInboxRoute) - expect(nextState.routes).toContain(RedirectToInboxRoute) - expect(replaceState).toBeA('function') - - replaceState(null, '/inbox') - }, - onLeave() { - expect(this).toBe(RedirectToInboxRoute) - } - } - - MessageRoute = { - path: 'messages/:messageID', - onEnter(nextState, replaceState) { - expect(this).toBe(MessageRoute) - expect(nextState.routes).toContain(MessageRoute) - expect(replaceState).toBeA('function') - }, - onLeave() { - expect(this).toBe(MessageRoute) - } - } - - DashboardRoute = { - component: Dashboard, - onEnter(nextState, replaceState) { - expect(this).toBe(DashboardRoute) - expect(nextState.routes).toContain(DashboardRoute) - expect(replaceState).toBeA('function') - }, - onLeave() { - expect(this).toBe(DashboardRoute) - }, - childRoutes: [ NewsFeedRoute, InboxRoute, RedirectToInboxRoute, MessageRoute ] - } - - routes = [ - DashboardRoute - ] - }) - - afterEach(function () { - unmountComponentAtNode(node) - }) - - beforeEach(function () { - shouldWarn('deprecated') - }) - - describe('and then navigates to another branch', function () { - it('calls the onLeave hooks of all routes in the previous branch that are not in the next branch', function (done) { - const history = createHistory('/inbox') - const dashboardRouteLeaveSpy = spyOn(DashboardRoute, 'onLeave').andCallThrough() - const inboxRouteEnterSpy = spyOn(InboxRoute, 'onEnter').andCallThrough() - const inboxRouteLeaveSpy = spyOn(InboxRoute, 'onLeave').andCallThrough() - - const steps = [ - function () { - expect(inboxRouteEnterSpy).toHaveBeenCalled('InboxRoute.onEnter was not called') - history.pushState(null, '/news') - }, - function () { - expect(inboxRouteLeaveSpy).toHaveBeenCalled('InboxRoute.onLeave was not called') - expect(dashboardRouteLeaveSpy.calls.length).toEqual(0, 'DashboardRoute.onLeave was called') - } - ] - - const execNextStep = execSteps(steps, done) - - render( - , node, execNextStep) - }) - }) - - describe('and then navigates to the same branch, but with different params', function () { - it('calls the onLeave and onEnter hooks of all routes whose params have changed', function (done) { - const history = createHistory('/messages/123') - const dashboardRouteLeaveSpy = spyOn(DashboardRoute, 'onLeave').andCallThrough() - const dashboardRouteEnterSpy = spyOn(DashboardRoute, 'onEnter').andCallThrough() - const messageRouteLeaveSpy = spyOn(MessageRoute, 'onLeave').andCallThrough() - const messageRouteEnterSpy = spyOn(MessageRoute, 'onEnter').andCallThrough() - - const steps = [ - function () { - expect(dashboardRouteEnterSpy).toHaveBeenCalled('DashboardRoute.onEnter was not called') - expect(messageRouteEnterSpy).toHaveBeenCalled('InboxRoute.onEnter was not called') - history.pushState(null, '/messages/456') - }, - function () { - expect(messageRouteLeaveSpy).toHaveBeenCalled('MessageRoute.onLeave was not called') - expect(messageRouteEnterSpy).toHaveBeenCalled('MessageRoute.onEnter was not called') - expect(dashboardRouteLeaveSpy.calls.length).toEqual(0, 'DashboardRoute.onLeave was called') - } - ] - - const execNextStep = execSteps(steps, done) - - render( - , node, execNextStep) - }) - }) - - describe('and then the query changes', function () { - it('calls the onEnter hooks of all routes in that branch', function (done) { - const newsFeedRouteEnterSpy = spyOn(NewsFeedRoute, 'onEnter').andCallThrough() - const history = createHistory('/inbox') - - render(, node, function () { - history.pushState(null, '/news', { q: 1 }) - expect(newsFeedRouteEnterSpy.calls.length).toEqual(1) - history.pushState(null, '/news', { q: 2 }) - expect(newsFeedRouteEnterSpy.calls.length).toEqual(1) - done() - }) - }) - }) - -}) diff --git a/modules/createMemoryHistory.js b/modules/createMemoryHistory.js index 1dcbf148e5..4c1e3ee44d 100644 --- a/modules/createMemoryHistory.js +++ b/modules/createMemoryHistory.js @@ -3,7 +3,7 @@ import useBasename from 'history/lib/useBasename' import baseCreateMemoryHistory from 'history/lib/createMemoryHistory' export default function createMemoryHistory(options) { - // signatures and type checking differ between `useRoutes` and + // signatures and type checking differ between `useQueries` and // `createMemoryHistory`, have to create `memoryHistory` first because // `useQueries` doesn't understand the signature const memoryHistory = baseCreateMemoryHistory(options) diff --git a/modules/createTransitionManager.js b/modules/createTransitionManager.js index b81c891686..f5f5dad001 100644 --- a/modules/createTransitionManager.js +++ b/modules/createTransitionManager.js @@ -1,5 +1,6 @@ -import warning from './routerWarning' import { REPLACE } from 'history/lib/Actions' + +import warning from './routerWarning' import computeChangedRoutes from './computeChangedRoutes' import { runEnterHooks, runChangeHooks, runLeaveHooks } from './TransitionUtils' import { default as _isActive } from './isActive' @@ -247,5 +248,3 @@ export default function createTransitionManager(history, routes) { listen } } - -//export default useRoutes diff --git a/modules/index.js b/modules/index.js index a1d5e2dc45..d53603e81e 100644 --- a/modules/index.js +++ b/modules/index.js @@ -12,8 +12,7 @@ export Route from './Route' /* utils */ export { createRoutes } from './RouteUtils' export RouterContext from './RouterContext' -export RoutingContext from './RoutingContext' -export PropTypes, { locationShape, routerShape } from './PropTypes' +export { locationShape, routerShape } from './PropTypes' export match from './match' export useRouterHistory from './useRouterHistory' export { formatPattern } from './PatternUtils'