Skip to content

Commit

Permalink
Update UniversalRouter to v4 (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzzy committed Sep 20, 2017
1 parent c176669 commit a9f37d7
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 26 deletions.
12 changes: 0 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ module.exports = {
},

rules: {
// `js` and `jsx` are common extensions
// `mjs` is for `universal-router` only, for now
'import/extensions': [
'error',
'always',
{
js: 'never',
jsx: 'never',
mjs: 'never',
},
],

// Not supporting nested package.json yet
// https://github.com/benmosher/eslint-plugin-import/issues/458
'import/no-extraneous-dependencies': 'off',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"serialize-javascript": "^1.3.0",
"source-map-support": "^0.4.15",
"sqlite3": "^3.1.8",
"universal-router": "^3.2.0",
"universal-router": "^4.0.0",
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function onLocationChange(location, action) {
// and whose action method returns anything other than `undefined`.
const route = await router.resolve({
...context,
path: location.pathname,
pathname: location.pathname,
query: queryString.parse(location.search),
});

Expand Down
4 changes: 2 additions & 2 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* LICENSE.txt file in the root directory of this source tree.
*/

import Router from 'universal-router';
import UniversalRouter from 'universal-router';
import routes from './routes';

export default new Router(routes, {
export default new UniversalRouter(routes, {
resolveRoute(context, params) {
if (typeof context.route.load === 'function') {
return context.route
Expand Down
8 changes: 4 additions & 4 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

// The top-level (parent) route
const routes = {
path: '/',
path: '',

// Keep in mind, routes are evaluated in order
children: [
{
path: '/',
path: '',
load: () => import(/* webpackChunkName: 'home' */ './home'),
},
{
Expand Down Expand Up @@ -44,9 +44,9 @@ const routes = {
load: () => import(/* webpackChunkName: 'admin' */ './admin'),
},

// Wildcard routes, e.g. { path: '*', ... } (must go last)
// Wildcard routes, e.g. { path: '(.*)', ... } (must go last)
{
path: '*',
path: '(.*)',
load: () => import(/* webpackChunkName: 'not-found' */ './not-found'),
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ app.get('*', async (req, res, next) => {

const route = await router.resolve({
...context,
path: req.path,
pathname: req.path,
query: req.query,
});

Expand Down
2 changes: 1 addition & 1 deletion tools/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const isVerbose = process.argv.includes('--verbose');
const isAnalyze =
process.argv.includes('--analyze') || process.argv.includes('--analyse');

const reScript = /\.jsx?$/;
const reScript = /\.m?jsx?$/;
const reStyle = /\.(css|less|scss|sss)$/;
const reImage = /\.(bmp|gif|jpe?g|png|svg)$/;
const staticAssetName = isDebug
Expand Down
12 changes: 8 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6035,6 +6035,10 @@ path-to-regexp@^1.7.0:
dependencies:
isarray "0.0.1"

path-to-regexp@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.0.0.tgz#b77a8168c2e78bc31f3d312d71b1ace97df23870"

path-type@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
Expand Down Expand Up @@ -8170,11 +8174,11 @@ unique-string@^1.0.0:
dependencies:
crypto-random-string "^1.0.0"

universal-router@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/universal-router/-/universal-router-3.2.0.tgz#4590ee42f55e2a08188c632070d90675bb2fa40f"
universal-router@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/universal-router/-/universal-router-4.0.0.tgz#0768ae131d6b5f25245fe2e8d9daa382d71c4303"
dependencies:
path-to-regexp "^1.7.0"
path-to-regexp "^2.0.0"

universalify@^0.1.0:
version "0.1.1"
Expand Down

0 comments on commit a9f37d7

Please sign in to comment.