Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next.js 自定义路由 #2

Closed
ghost opened this issue Jan 17, 2019 · 1 comment
Closed

next.js 自定义路由 #2

ghost opened this issue Jan 17, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 17, 2019

我想实现自定义路由/detail/2333

const express = require('express');
const next = require('next');

const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

app.prepare().then(() => {
    const server = express();
    server.get('/detail/:id', (req, res) => {
        const actualPage = '/detail';
        return app.render(req, res, actualPage);
    });
    server.get('*', (req, res) => {
        handle(req, res);
    });
    server.listen(8060, '0.0.0.0');
});

可是这样写没有效果,连服务都起不来了
求助

@ghost ghost closed this as completed Jan 18, 2019
@raoenhui
Copy link
Owner

报什么错,有截图吗,如果是npm包的问题,建议可以用yarn && yarn dev

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant