Ich bin neu in React/Express/Node Welt und ich studiere eine App, die dem Benutzer ermöglicht, ein Login und eine API zu erstellen, die Aufgaben erstellen.TypeError: app.route ist keine Funktion
Ich versuche, beide zusammen in der gleichen Anwendung zu setzen, aber wenn ich eine GET für die Liste der Aufgaben nennen, habe ich diesen Fehler:
TypeError: app.route is not a function
at module.exports (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/server/routes/schedule.js:6:7)
at Layer.handle [as handle_request] (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:317:13)
at /home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:335:12)
at next (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:275:10)
at initialize (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/passport/lib/middleware/initialize.js:53:5)
at Layer.handle [as handle_request] (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:317:13)
at /home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:335:12)
at next (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:275:10)
at urlencodedParser (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/body-parser/lib/types/urlencoded.js:91:7)
at Layer.handle [as handle_request] (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:317:13)
at /home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:284:7
Dies ist der Code-Schnipsel des Todolist. js in route ordner:
'use strict';
module.exports = function(app) {
var todoList = require('../controllers/todoListController');
// todoList Routes
app.route('/tasks')
.get(todoList.list_all_tasks)
.post(todoList.create_a_task);
app.route('/tasks/:taskId')
.get(todoList.read_a_task)
.put(todoList.update_a_task)
.delete(todoList.delete_a_task);
};
Das ist noch etwas, das ich verpasst habe? Das ist der Ausschnitt aus dem Teil der Authentication-Anwendung, die in der gleichen Strecke Ordner funktioniert gut:
const express = require('express');
const router = new express.Router();
router.get('/dashboard', (req, res) => {
res.status(200).json({
message: "You're authorized to see this secret message."
});
});
module.exports = router;
ich Hilfe für diese zu schätzen wissen;)
Das ist mein Repository https://github.com/slaurianodev/agenda-app. Fühlen Sie sich frei, dieses Problem zu klonen und zu helfen.
Tks
Sergio
der Fehler ist ziemlich klar. du exportierst eine Funktion aus 'scheduleRoutes', aber dann übergibst du' app' nicht an – azium
Wie könnte ich das lösen? –