diff --git a/CHANGELOG.md b/CHANGELOG.md index cfe9dfbbd..a88fcf860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## HEAD +- Fixed: navigation now offers a proper scroll behavior. + Not more weird page updates. + ([#285](https://github.com/MoOx/phenomic/issues/285) - @MoOx) + ### Boilerplate - Added: ``PageLoading`` now use "Loading..." has a title diff --git a/interfaces/external-modules/react-router-scroll.js b/interfaces/external-modules/react-router-scroll.js new file mode 100644 index 000000000..86823738d --- /dev/null +++ b/interfaces/external-modules/react-router-scroll.js @@ -0,0 +1,4 @@ +declare module "react-router-scroll" { + declare var exports: + (shouldUpdateScroll?: () => boolean | Array) => Function; +} diff --git a/interfaces/external-modules/react-router.js b/interfaces/external-modules/react-router.js new file mode 100644 index 000000000..107b4f79b --- /dev/null +++ b/interfaces/external-modules/react-router.js @@ -0,0 +1,36 @@ +declare module "react-router" { + declare interface ReactRouter { + IndexRoute: React.Component; + Link: React.Component; + Redirect: React.Component; + IndexRedirect: React.Component; + Route: React.Component; + Router: React.Component; + browserHistory: any; + useRouterHistory: + (historyFactory: Function) => (options: ?Object) => Object; + match: Function; + RouterContext: React.Component; + createRoutes: (routes: React$Element) => Array; + formatPattern: (pattern: string, params: Object) => string; + applyRouterMiddleware: Function; + } + declare var exports: ReactRouter; +} + +declare module "react-router/lib/PatternUtils" { + declare var exports: any; +} + +declare module "history/lib/createBrowserHistory" { + declare var exports: any; +} + +export type ReactRouterProps = { + history: Object, + location: Object, + params: Object, + route: Object, + routeParams: Object, + routes: Array, +} diff --git a/package.json b/package.json index d0a0c9401..20c977f07 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "opn": "^4.0.2", "pify": "^2.3.0", "portfinder": "^1.0.2", + "react-router-scroll": "^0.2.0", "redbox-react": "^1.2.2", "remark": "^4.1.1", "remark-autolink-headings": "^3.0.0", diff --git a/src/client/index.js b/src/client/index.js index feb19acb2..f689075d4 100644 --- a/src/client/index.js +++ b/src/client/index.js @@ -2,8 +2,9 @@ // App import React from "react" import ReactDOM from "react-dom" -import { Router, useRouterHistory } from "react-router" +import { Router, useRouterHistory, applyRouterMiddleware } from "react-router" import createBrowserHistory from "history/lib/createBrowserHistory" +import useScroll from "react-router-scroll" import { Provider as ReduxContextProvider } from "react-redux" import PhenomicContextProvider from "../ContextProvider" @@ -35,7 +36,11 @@ export default function phenomic({ metadata={ metadata } > - + , document.getElementById("phenomic")