From 08e84941705fcae0eb55af1079205d21075d6682 Mon Sep 17 00:00:00 2001 From: William Chargin Date: Fri, 20 Jul 2018 19:09:35 -0700 Subject: [PATCH] Update page title on route change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test Plan: Navigate to `/`, then click the “Explorer” link, and note that the page title has updated. wchargin-branch: update-page-title --- src/app/App.js | 14 ++++++++++++-- src/app/routes.js | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/app/App.js b/src/app/App.js index 45d6ec1..f40e30f 100644 --- a/src/app/App.js +++ b/src/app/App.js @@ -3,10 +3,20 @@ import React from "react"; import {Router, browserHistory} from "react-router"; -import {createRoutes} from "./routes"; +import {createRoutes, resolveTitleFromPath} from "./routes"; export default class App extends React.Component<{}> { render() { - return ; + return ( + + ); } } diff --git a/src/app/routes.js b/src/app/routes.js index 4798b07..fc480a8 100644 --- a/src/app/routes.js +++ b/src/app/routes.js @@ -40,3 +40,19 @@ export function createRoutes() { ); } + +function resolveRouteFromPath(path: string): ?RouteDatum { + const matches = (candidateRoute) => { + const candidatePath = candidateRoute.path; + const start = path.substring(0, candidatePath.length); + const end = path.substring(candidatePath.length); + return start === candidatePath && (end.length === 0 || end === "/"); + }; + return routeData.filter(matches)[0] || null; +} + +export function resolveTitleFromPath(path: string): string { + const route = resolveRouteFromPath(path); + const fallback = "SourceCred"; + return route ? route.title : fallback; +}