Routing in a Marko.js application can be set up using a router like express for server-side routing. Here’s a basic example:
Install express:
npm install express
Set up routing in your server file (e.g., server.js):
const express = require('express');
const markoExpress = require('@marko/express');
const app = express();
app.use(markoExpress());
const Home = require('./src/pages/home.marko');
const About = require('./src/pages/about.marko');
app.get('/', (req, res) => res.marko(Home));
app.get('/about', (req, res) => res.marko(About));
app.listen(3000, () => console.log('Server is running on http://localhost:3000'));
Create the Marko templates (e.g., home.marko and about.marko):
// home.marko
<template>
<h1>Home Page</h1>
<a href="/about">About</a>
</template>
// about.marko
<template>
<h1>About Page</h1>
<a href="/">Home</a>
</template>
In this example, we set up a basic Express server that handles routing to a home page and an about page.