Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('creates a cache entry for each exact/strict pair', () => {
// true/false and false/true will collide when adding booleans
const trueFalse = matchPath('/one/two', {
path: '/one/two/',
exact: true,
strict: false
});
const falseTrue = matchPath('/one/two', {
path: '/one/two/',
exact: false,
strict: true
});
expect(!!trueFalse).toBe(true);
expect(!!falseTrue).toBe(false);
});
});
it('creates a cache entry for each exact/strict pair', () => {
// true/false and false/true will collide when adding booleans
const trueFalse = matchPath('/one/two', {
path: '/one/two/',
exact: true,
strict: false
});
const falseTrue = matchPath('/one/two', {
path: '/one/two/',
exact: false,
strict: true
});
expect(!!trueFalse).toBe(true);
expect(!!falseTrue).toBe(false);
});
});
routes.some(route => {
const match = route.path
? matchPath(pathname, route)
: branch.length
? branch[branch.length - 1].match // use parent match
: computeMatch(pathname); // use default "root" match
if (match) {
branch.push({ route, match });
if (route.routes) {
matchRoutes(route.routes, pathname, branch);
}
}
return match;
});
it('returns correct url at "/somewhere/else"', () => {
const path = '/';
const pathname = '/somewhere/else';
const match = matchPath(pathname, path);
expect(match.url).toBe('/');
});
});
it('returns non-sensitive url', () => {
const options = {
path: '/SomeWhere'
};
const pathname = '/somewhere';
const match = matchPath(pathname, options);
expect(match.url).toBe('/somewhere');
});
it('returns correct url at "/"', () => {
const path = '/';
const pathname = '/';
const match = matchPath(pathname, path);
expect(match.url).toBe('/');
});
it('returns correct url at "/somewhere/else"', () => {
const path = '/somewhere';
const pathname = '/somewhere/else';
const match = matchPath(pathname, path);
expect(match.url).toBe('/somewhere');
});
});
it('matches the root URL', () => {
const match = matchPath('/test-location/7', {});
expect(match.path).toBe('/');
expect(match.url).toBe('/');
expect(match.isExact).toBe(false);
expect(match.params).toEqual({});
});
});
it('returns sensitive url', () => {
const options = {
path: '/SomeWhere',
sensitive: true
};
const pathname = '/somewhere';
const match = matchPath(pathname, options);
expect(match).toBe(null);
});
});
app.get('*', (req, res) => {
/** Generate props for the mathing components in the router */
const props = matchPath(routes, req.url)
const App = createElement(StaticRouter, props)
const MatchURL = URLs.filter(item => item.url == req.url)[0]
/** Render to string the generated JSX tree */
const JSX = renderToStaticMarkup(App)
/** Extract html, css string, plus an ids array for hydratation */
const { css, html, ids } = SSR.extract(JSX)
const IDs = JSON.stringify(ids)
/** Render the page to the user based on the template */
res.send(
TEMPLATE
.replace(/\r?\n|\r/g, '')
.replace('{{TITLE}}', MatchURL ? MatchURL.title : 'Page Not Found')
.replace('{{CSS}}', css)