Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Fix unintentional regressions from removing extraneous slash support (#8
Browse files Browse the repository at this point in the history
)
  • Loading branch information
taion committed Apr 11, 2016
1 parent ceaa807 commit a264ca2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/__tests__/_bc-Link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('v1 Link', function () {
Michael
</Link>
<Link
to="/hello/ryan" query={{ the: 'query' }}
to="hello/ryan" query={{ the: 'query' }}
activeClassName="active"
>
Ryan
Expand Down
10 changes: 10 additions & 0 deletions modules/__tests__/serverRendering-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ describe('server rendering', function () {
})
})

it('supports basenames with trailing slash', function (done) {
match({ routes, location: '/dashboard', basename: '/nasebame/' }, function (error, redirectLocation, renderProps) {
const string = renderToString(
<RouterContext {...renderProps} />
)
expect(string).toMatch(/\/nasebame/)
done()
})
})

describe('server/client consistency', function () {
// Just render to static markup here to avoid having to normalize markup.

Expand Down
7 changes: 7 additions & 0 deletions modules/isActive.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ function getMatchingRouteIndex(pathname, activeRoutes, activeParams) {
* and params.
*/
function routeIsActive(pathname, routes, params, indexOnly) {
// TODO: This is a bit ugly. It keeps around support for treating pathnames
// without preceding slashes as absolute paths, but possibly also works
// around the same quirks with basenames as in matchRoutes.
if (pathname.charAt(0) !== '/') {
pathname = `/${pathname}`
}

const i = getMatchingRouteIndex(pathname, routes, params)

if (i === null) {
Expand Down
19 changes: 15 additions & 4 deletions modules/matchRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,23 @@ function matchRouteDeep(
* Note: This operation may finish synchronously if no routes have an
* asynchronous getChildRoutes method.
*/
function matchRoutes(
export default function matchRoutes(
routes, location, callback,
remainingPathname=location.pathname, paramNames=[], paramValues=[]
remainingPathname, paramNames=[], paramValues=[]
) {
if (remainingPathname === undefined) {
// TODO: This is a little bit ugly, but it works around a quirk in history
// that strips the leading slash from pathnames when using basenames with
// trailing slashes.
if (location.pathname.charAt(0) !== '/') {
location = {
...location,
pathname: `/${location.pathname}`
}
}
remainingPathname = location.pathname
}

loopAsync(routes.length, function (index, next, done) {
matchRouteDeep(
routes[index], location, remainingPathname, paramNames, paramValues,
Expand All @@ -197,5 +210,3 @@ function matchRoutes(
)
}, callback)
}

export default matchRoutes

0 comments on commit a264ca2

Please sign in to comment.