node.js - Take a param from the home page, without it breaking the routes -


let's have mywebsite.com , mywebsite.com/login

i have route index page , route login page.

i working on feature now, take id such mywebsite.com/t9wfhash

if there such id, query db something.

i tried like

/* index page. */ router.get('/:urlid', function (req, res) {    if ( req.params.urlid !== 'undefined' ) {     console.log(req.params.urlid);     var urlid = req.params.urlid;   }    if (req.isauthenticated()) {     res.redirect('/dashboard');   }   res.render('index', { title: urlid }); }); 

however, login page doesn't work anymore when taking id index page (:urlid) -- if go login page console logs "login", of course.

so how can make if goes 1 of routes (ie login page), it's not considered id.

any ideas appreciated.

as long register login route before urlid route, request /login trigger login route instead of urlid route:

var express = require('express'); var app = express();  app.get('/', function(req, res){   res.send('hello world'); });  app.get('/login', function(req, res){   res.send('this login page'); });  app.get('/:urlid', function(req, res){   res.send( req.params.urlid ); });  app.listen(3005);  // http://localhost:3005/login return "this login page" // http://localhost:3005/22 return 22 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -