From 19cca9c50798271257d7757548986e7b5aa11c02 Mon Sep 17 00:00:00 2001 From: Tyler Thompson Date: Mon, 25 Jul 2016 19:33:05 -0700 Subject: [PATCH 1/2] Stop using createHref (adds duplicate base names); match against the pathname instead of the url to avoid hardcoded base names --- src/fragment.js | 7 +++++-- src/link.js | 5 ++++- src/reducer.js | 2 +- src/store-enhancer.js | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/fragment.js b/src/fragment.js index 3a6b144b..508ce0bd 100644 --- a/src/fragment.js +++ b/src/fragment.js @@ -5,13 +5,16 @@ const Fragment = (props, context) => { const { forRoute, forRoutes, withConditions, children } = props; const { router: location } = context.router.store.getState(); - if (forRoute && !new UrlPattern(forRoute).match(location.url)) { + if ( + forRoute && + !new UrlPattern(forRoute).match(location.pathname) + ) { return null; } if (forRoutes) { const anyMatch = forRoutes.some(route => - new UrlPattern(route).match(location.url) + new UrlPattern(route).match(location.pathname) ); if (!anyMatch) { diff --git a/src/link.js b/src/link.js index 3899aba2..7047319a 100644 --- a/src/link.js +++ b/src/link.js @@ -4,6 +4,9 @@ import { PUSH, REPLACE } from './action-types'; const LEFT_MOUSE_BUTTON = 0; +const normalizeHref = location => + `${location.basename || ''}${location.pathname}`; + const normalizeLocation = href => { if (typeof href === 'string') { const [pathname, query] = href.split('?'); @@ -74,7 +77,7 @@ const Link = (props, context) => { onClick({ e, target, diff --git a/src/reducer.js b/src/reducer.js index 6c9b0428..7b53f326 100644 --- a/src/reducer.js +++ b/src/reducer.js @@ -3,7 +3,7 @@ import { LOCATION_CHANGED } from './action-types'; export default (state = {}, action) => { if (action.type === LOCATION_CHANGED) { // No-op the initial route action - if (state && state.url === action.payload.url) { + if (state && state.pathname === action.payload.pathname) { return state; } diff --git a/src/store-enhancer.js b/src/store-enhancer.js index dd942b37..02e5ca39 100644 --- a/src/store-enhancer.js +++ b/src/store-enhancer.js @@ -5,6 +5,7 @@ import routerReducer from './reducer'; export const locationDidChange = ({ location, matchRoute }) => { // Build the canonical URL + // Don't use this for matching const { basename, pathname } = location; const trailingSlash = /\/$/; const url = `${basename || ''}${pathname}` @@ -14,7 +15,7 @@ export const locationDidChange = ({ location, matchRoute }) => { type: LOCATION_CHANGED, payload: { ...location, - ...matchRoute(url), + ...matchRoute(pathname), url } }; From c06826d5b6d9165d51b97636a602b5ecaee4eb6f Mon Sep 17 00:00:00 2001 From: Tyler Thompson Date: Mon, 25 Jul 2016 19:42:00 -0700 Subject: [PATCH 2/2] Fix reducer test --- test/spec/reducer.spec.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/spec/reducer.spec.jsx b/test/spec/reducer.spec.jsx index 2288f0bc..0dbcc59f 100644 --- a/test/spec/reducer.spec.jsx +++ b/test/spec/reducer.spec.jsx @@ -9,6 +9,7 @@ describe('Router reducer', () => { params: {}, result: 'rofl', url: '/rofl', + pathname: '/rofl', action: 'PUSH', state: { bork: 'bork' @@ -21,6 +22,7 @@ describe('Router reducer', () => { params: {}, result: 'rofl', url: '/rofl', + pathname: '/rofl', action: 'PUSH', state: { bork: 'bork'