creativetimofficial / ct-nextjs-argon-dashboard-pro

NextJS version of Argon Dashboard PRO React
7 stars 3 forks source link

[Bug] Internal Sever Error when path end with slash #4

Open eddiekoh opened 3 years ago

eddiekoh commented 3 years ago

Version

1.1.0

Reproduction link

https://www.creative-tim.com/product/nextjs-argon-dashboard-pro

Operating System

MacOS

Device

Laptop

Browser & Version

All Browser

Steps to reproduce

  1. download a fresh copy of NextJS Argon Dashboard PRO v1.1.-
  2. run npm run install
  3. run npm run build
  4. run npm start
  5. go to http://localhost:3000/admin/dashboard/
  6. go to http://localhost:3000/admin/dashboard/ AGAIN
  7. browser showing internal server error

What is expected?

Expect the mage to be redirected to http://localhost:3000/admin/dashboard

What is actually happening?

it is showing error instead


Solution

Additional comments

einazare commented 3 years ago

Hello there, @eddiekoh ,

Thank you for your interest in working with our products. You access an inexistent route, please, instead of

This will solve your issue.

Best, Manu

eddiekoh commented 3 years ago

Thanks for the fast reply @EINazare ,

NextJS will do a redirect http://localhost:3000/admin/dashboard/ to http://localhost:3000/admin/dashboard if you try on other page that didn't use ./variables/charts.js then the redirect will happen.

if (typeof window === "undefined") { global.window = {}; } if (typeof document === "undefined") { global.document = { querySelector: () => {}, }; }

This block us causing error with NextJS

einazare commented 3 years ago

Hello again, @eddiekoh ,

Go inside pages/admin/dashboard.js and change:

                  <Line
                    data={chartExample1[chartExample1Data]}
                    options={chartExample1.options}
                    id="chart-sales-dark"
                    className="chart-canvas"
                  />

To:

                  {
                    typeof window !== "undefined" && <Line
                      data={chartExample1[chartExample1Data]}
                      options={chartExample1.options}
                      id="chart-sales-dark"
                      className="chart-canvas"
                    />
                  }

And also, change:

                  <Bar
                    data={chartExample2.data}
                    options={chartExample2.options}
                    className="chart-canvas"
                    id="chart-bars"
                  />

To:

                  {
                    typeof window !== "undefined" && <Bar
                      data={chartExample2.data}
                      options={chartExample2.options}
                      className="chart-canvas"
                      id="chart-bars"
                    />
                  }

This will do the trick.

NOTE: Everywhere we use the chart.js and react-chartjs-2 you will need to add that:

                  {
                    typeof window !== "undefined" && ...render code of chart here
                  }

Best, Manu

eddiekoh commented 3 years ago

Thanks, this will fix my issue since I'm not using the demo chart.