fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

isNextPath is not a function #70

Closed theednaffattack closed 7 years ago

theednaffattack commented 7 years ago

Hi I'm using next-routes "^1.0.20" currently. I should note that I also tried upgrading to the newest next beta and next-routes 1.0.40, but got the same "TypeError: routes.isNextPath is not a function" error in my console.

While poking around for answers I found a few github issues where you've referenced this function. Would you mind helping me out? For some reason I can't find this function inside next-routes or next and I'm not sure what I'm getting wrong.

An Issue where you suggested it https://github.com/fridays/next-routes/issues/4#issuecomment-279955172

I thought I might be misunderstand something inside nextjs and saw another comment from you here: https://github.com/zeit/next.js/issues/1627#issuecomment-292092951

My app is getting bogged down inside an if statement. Removing reference to isNextPath "!routes.isNextPath(req.url) &&" (in my forked code and pasted below) allows the app to run but I assume I lose SSR caching as a result(?)

Here's the code:

/server/session.js

const session = require('express-session');
const FileStore = require('session-file-store')(session);
const { SESSION_SECRET } = require('./config');
const acceptLanguage = require('./acceptLanguage');
const routes = require('../universal/routes');

// TODO store more persistently (this only survives while deployment is on same machine)
const store = new FileStore({ path: '/tmp/sessions' });

module.exports = {
  configSession: session({
    secret: SESSION_SECRET,
    store,
    resave: false,
    rolling: true,
    saveUninitialized: true,
    httpOnly: true,
  }),
  defaultSessionData(req, res, next) {
    if (!routes.isNextPath(req.url) && !req.session.user) {
      req.session.user = { // eslint-disable-line no-param-reassign
        locale: acceptLanguage(req),
      };
    }
    next();
  },
};

/universal/routes.js

const nextRoutes = require('next-routes');

module.exports = nextRoutes()
  .add('/', 'index')
  .add('about')
  .add('discover')
  .add('retreat', '/retreat/:id')
  .add('track', '/track/:id')
  .add('profile', '/:slug');

Thanks

fridays commented 7 years ago

Hi @theednaffattack the function was used to prevent a problem with catchall routes and rendering, but is no longer needed since Next does it internally now. You could use that method instead if you need it for something. Sorry for the confusion!