diff --git a/ProjectSourceCode/src/resources/js/homepage/create-league-routes.js b/ProjectSourceCode/src/resources/js/homepage/create-league-routes.js deleted file mode 100644 index ec5b351..0000000 --- a/ProjectSourceCode/src/resources/js/homepage/create-league-routes.js +++ /dev/null @@ -1,25 +0,0 @@ -// create-league-routes.js - -const express = require('express'); -const exphbs = require('express-handlebars'); - -const app = express(); - -app.engine('hbs', exphbs({ extname: '.hbs' })); -app.set('view engine', 'hbs'); - -// Define the redirectToLeaguePage function -function redirectToLeaguePage(leagueName) { - window.location.href = '/views/pages/league-page/league-page.hbs?leagueName=' + encodeURIComponent(leagueName); -} - -// Define a route to render the league-page.hbs template -app.get('/league-page/:leagueName', (req, res) => { - const leagueName = req.params.leagueName; - // Here you might fetch data related to the clicked league - // Pass the data to the template and render it - res.render('league-page/league-page', { leagueName }); -}); - -// Export the app and redirectToLeaguePage function -module.exports = { app, redirectToLeaguePage }; diff --git a/ProjectSourceCode/src/resources/js/homepage/generate-league-routes.js b/ProjectSourceCode/src/resources/js/homepage/generate-league-routes.js new file mode 100644 index 0000000..4a6883b --- /dev/null +++ b/ProjectSourceCode/src/resources/js/homepage/generate-league-routes.js @@ -0,0 +1,12 @@ +const express = require('express'); +const app = express(); + +// Define a route to handle requests to "/league/:leagueName" +app.get('/league/:leagueName', (req, res) => { + // Extract the league name from the URL parameters + const leagueName = req.params.leagueName; + + // Render the league page template using Handlebars + res.render('partials/league-page/league-page', { leagueName: leagueName }); +}); + diff --git a/ProjectSourceCode/src/resources/js/homepage/redirect-to-league-url.js b/ProjectSourceCode/src/resources/js/homepage/redirect-to-league-url.js new file mode 100644 index 0000000..a9445ef --- /dev/null +++ b/ProjectSourceCode/src/resources/js/homepage/redirect-to-league-url.js @@ -0,0 +1,7 @@ +function redirectToLeaguePage(leagueName) { + // Append the league name to the URL + var url = "/league/" + leagueName.toLowerCase().replace(/\s+/g, '-'); + + // Redirect to the league page + window.location.href = url; +} \ No newline at end of file diff --git a/ProjectSourceCode/src/views/pages/home.hbs b/ProjectSourceCode/src/views/pages/home.hbs index 06ffb2d..3659c87 100644 --- a/ProjectSourceCode/src/views/pages/home.hbs +++ b/ProjectSourceCode/src/views/pages/home.hbs @@ -4,32 +4,32 @@