【问题标题】:Nuxt routing failing to create sub-route on buildNuxt 路由无法在构建时创建子路由
【发布时间】:2021-04-26 05:28:57
【问题描述】:

为了展示一个产品,我想用这个结构来做链接:

/collections/:slug/:id

到目前为止,我已经创建了这个文件夹结构:

 collections/
     _category/
        _id.vue
   _slug.vue
   index.vue

_slug.vue 和 index.vue 在 collections 文件夹中。

在本地一切运行正常,但是当我让 npm run dist 和 push to live 时,尝试访问时:

/collections/_category or /collections/_category/_id

没有找到。

我应该进行哪些更改才能使其正常工作?

还有一件事要提的是,当从主页访问产品时,一切正常并且产品已显示,但是当我尝试刷新该页面时,我得到 404 notfound,ngnix。会不会是ngnix的问题? Nginx 配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/{link_to_the_project}/dist;

    server_name {mydomainname}.ro;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
    }

    location ~ /\.ht {
            deny all;
    }
}

【问题讨论】:

  • 尝试yarn buildyarn generate(如果你要完全静态)然后yarn start 看看有什么问题。由于它是本地的,但与生产环境几乎相同,它将帮助您更快地调试它。

标签: nginx npm nuxt.js


【解决方案1】:

在我让它工作之后,我什至不知道它之前是如何工作的......

它对我的工作方式:

将项目中的所有文件提交并推送到服务器。通过 ssh 连接到服务器并在服务器上运行:npm install

安装 npm 后,我已将我的 nginx 配置修改为:

 server {
    listen 80;
    server_name {mydomain}.ro;

    location / {
            proxy_pass http://127.0.0.1:3000;//run `npm run start` in project for ip
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }
 }

已安装 pm2:

 npm install pm2 -g

然后运行:

 pm2 start npm -- start

现在一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    相关资源
    最近更新 更多