Routing not working in my site

Layout file: views/layouts/main.ejs

Page files: views/about.ejs, views/homepage.ejs

My routes.json is configured as follows:

{
  "routes": [
    {
      "path": "/",
      "page": "homepage",
      "layout": "main"
    },
    {
      "path": "/about",
      "page": "about",
      "layout": "main"
    }
  ]
}

In main.ejs, I have:

<main is="dmx-view" id="content">
  <%- await include(content, locals); %>
</main>

When I try to access the /about page in the browser, I get the following error:

{"status":"404","message":"/about not found."}

Things I Have Checked

The views/about.ejs file exists
The main.ejs layout file is working properly
/about is correctly defined in routes.json
The about.ejs file includes the following meta tag at the top:

<meta name="ac:route" content="/about">

Actually, Wappler makes routing really easy. I just can't figure out what I'm missing.
Any help would be greatly appreciated!

In my layout files, the main DIV is nested within a BODY.

<body is="dmx-app" id="fanlayout">
  <div is="dmx-view" id="content">
    <%- await include(content, locals); %>
  </div>
  <script src="/bootstrap/5/js/bootstrap.bundle.min.js"></script>
</body>

It just looks like your relative paths aren't resolving to what you'd expect. Do other content.ejs files work with this same layout page?

1 Like

Thanks for the reply! Actually, none of the routes are working — not just /about. I’ve tried several, like /homepage, /solutions, etc., and all of them return a 404 error.

I’m using main.ejs as my layout and placing <%- await include(content, locals); %> inside the main content div. The page files like about.ejs and homepage.ejs are in the views/ folder, and I have them correctly listed in routes.json.

Maybe I’m misunderstanding how Wappler SSR routing works — do I need to define the routes manually in server.js or is routes.json enough?

Please check the web server logs tab in Wappler, I suspect you have an error and routes aren't being loaded

1 Like

Thanks everyone, I solved the issue after following your suggestions. Really appreciate the help!

1 Like

This is becoming increasingly common, the local server stalls but shows as running.
This then seems to leads to failed routing and old,presumably cached, content particulary old api actions running after editing them.
I must restart the server 20 times a day

1 Like

Alright, I’m officially joining the “20 restarts a day” club :sweat_smile: Honestly, this really put my mind at ease, thank you!

i often get a warning now, seems that the database connection also fails, who knows maybe the cause?

i get this a lot at point of failure:

{"status":"500","code":"ER_ACCESS_DENIED_ERROR","message":"Access denied for user 'userxxxx'@'localhost' (using password: YES)","stack":"Error: Access denied for user 'userxxxx'@'localhost' (using password: YES)\n at Packet.asError (E:\webs\site\node_modules\mysql2\lib\packets\packet.js:740:17)\n at ClientHandshake.execute (E:\webs\site\node_modules\mysql2\lib\commands\command.js:29:26)\n at Connection.handlePacket (E:\webs\site\node_modules\mysql2\lib\base\connection.js:475:34)\n at PacketParser.onPacket (E:\webs\site\node_modules\mysql2\lib\base\connection.js:93:12)\n at PacketParser.executeStart (E:\webs\site\node_modules\mysql2\lib\packet_parser.js:75:16)\n at Socket. (E:\webs\site\node_modules\mysql2\lib\base\connection.js:100:25)\n at Socket.emit (node:events:518:28)\n at addChunk (node:internal/streams/readable:561:12)\n at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)\n at Readable.push (node:internal/streams/readable:392:5)"}

This has been resolved in the last Wappler 7.3.6 update

Sorry George but it hasnt, still a problem.

What exactly is still a problem that the server stacks or database error occurs? Do you have a logging of that?

The database issue may or may not be rekated. I have captured a logfile already but the log does not seem to be anything relevant. I will pm it to you.

The main issue i am experiencing now is relating to server actions.
I make SA changes but the are not reflected in the local server output, the old version is served.
I have to restart the server to get the changes served. Not been able to capture that one yet but will try to get you a log.