Skip to content
This repository was archived by the owner on Dec 15, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { PUSH, REPLACE } from './action-types';

const LEFT_MOUSE_BUTTON = 0;

const normalizeHref = location =>
`${location.basename || ''}${location.pathname}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we validate basename to ensure it includes a / char?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 95.2345% sure history does this under the hood when you call history.createLocation()


const normalizeLocation = href => {
if (typeof href === 'string') {
const [pathname, query] = href.split('?');
Expand Down Expand Up @@ -74,7 +77,7 @@ const Link = (props, context) => {
<a
className={props.className}
style={props.style}
href={router.history.createHref(location)}
href={normalizeHref(location)}
onClick={e => onClick({
e,
target,
Expand Down
2 changes: 1 addition & 1 deletion src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/store-enhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand All @@ -14,7 +15,7 @@ export const locationDidChange = ({ location, matchRoute }) => {
type: LOCATION_CHANGED,
payload: {
...location,
...matchRoute(url),
...matchRoute(pathname),
url
}
};
Expand Down
2 changes: 2 additions & 0 deletions test/spec/reducer.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Router reducer', () => {
params: {},
result: 'rofl',
url: '/rofl',
pathname: '/rofl',
action: 'PUSH',
state: {
bork: 'bork'
Expand All @@ -21,6 +22,7 @@ describe('Router reducer', () => {
params: {},
result: 'rofl',
url: '/rofl',
pathname: '/rofl',
action: 'PUSH',
state: {
bork: 'bork'
Expand Down