Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6869691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:35:22+00:00 2026-05-27T03:35:22+00:00

I have many routes like: //routes app.get(page1/:action, function(req, res) { … } app.get(page2/:action, function(req,

  • 0

I have many routes like:

//routes
app.get("page1/:action", function(req, res) {
  ...
}

app.get("page2/:action", function(req, res) {
  ...
}

where page1 and page2 are two controllers and the :action is the “method” I need to call. The pages should be:

  1. /page1/delete
  2. /page1/modify
  3. /page1/add

I try to organize my code to simplify the job following a MVC system.
Could someone give me an advice regarding, how can I call the method of a controller by reading the parameter I use as :action I need to check if the method exists if not (if someone write /page1/blablabla) I return a 404 http error.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:35:23+00:00Added an answer on May 27, 2026 at 3:35 am

    Here’s an example on how to achieve this. You can read more on this on the Expressjs guide: http://expressjs.com/guide/error-handling.html

    function NotFound(msg){
      this.name = 'NotFound';
      Error.call(this, msg);
      Error.captureStackTrace(this, arguments.callee);
    }
    NotFound.prototype.__proto__ = Error.prototype;
    
    //routes
    app.get("page1/:action", function(req, res) {
      switch(req.params.action) {
        case 'delete':
          // delete 'action' here..
          break;
        case 'modify':
          // delete 'modify' here..
          break;
        case 'add':
          // delete 'add' here..
          break;
        default:
          throw new NotFound(); // 404 since action wasn't found
          // or you can redirect
          // res.redirect('/404');
      }
    }
    
    app.get('/404', function(req, res){
      throw new NotFound;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Orders can have many states. I would like to create named routes for those.
I have two models with a has-many/belongs-to relationship. The routes are nested, and I
I have this two routes currently in my application after decommenting out many other
Is it possible to split Rails 3.X routes.rb file? We have so many resources
In my Rails app I have a fairly standard has_many relationship between two entities.
I currently have a routes.rb file that looks like this: map.resources :profiles do |profile|
I have 2 models that I would like to setup routes for: Apps and
Given I have two models: company and location . A company has many locations
I have two associated tables. Venues and Specials . A venue can have many
I have a web app and I would like to prevent DOS attacks by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.