我需要在react-router v4中传递带有history.push的参数。
特别是pathname
和search
。
history.push(targetLocation.pathname + targetLocation.search)
现在它可以工作了,因为我使用了字符串连接。也许可以在没有连接的情况下进行传达?
答案 0 :(得分:0)
你可以这样做:
const express = require("express");
const app = express();
const Instagram = require("instagram-web-api");
const FileCookieStore = require("tough-cookie-filestore2");
const cookieStore = new FileCookieStore("./cookies.json");
var isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);
const PORT = process.env.PORT || 3000;
app.use(express.json());
var usernameArray = [
'instagramusername1',
'instagramusername2'
];
let randomUsername = usernameArray[Math.floor(Math.random() * usernameArray.length)]
const client = new Instagram({
username: (randomUsername),
password: "password for both accounts",
cookieStore,
});
app.get("/", (req, res) => {
res.send("Hello To Your Instagram Server");
});
app.get("/account/:userName", (req, res) => {
const user_name = req.params.userName;
(async () => {
const instagram_user = await client.getUserByUsername({
username: `${user_name}`,
});
res.json(instagram_user);
})();
});
app.get("/search/:q", (req, res) => {
const query = req.params.q;
(async () => {
const resulte = await client.search({ query: query });
const data = await JSON.stringify(resulte);
if (isHTML(String(data))) {
console.log("Must Login");
await client.login();
const tryagin = await client.search({ query: query });
res.send(tryagin);
} else {
console.log("no login");
res.send(resulte);
}
})();
});
app.get("/login", (req, res) => {
(async () => {
const user = await client.login();
if (user.authenticated == false) {
res.status(401).send(user);
} else {
res.status(200).send(user);
}
})();
});
app.get("/logout", (req, res) => {
(async () => {
client.logout();
res.send({ statu: "Logout" });
console.log("done");
})();
});
app.listen(PORT, () => {
console.log(`Example app listening at http://localhost:${PORT}`);
});