Javascript 提交表单firestore for web后如何重定向到新创建的文档页面

Javascript 提交表单firestore for web后如何重定向到新创建的文档页面,javascript,google-cloud-firestore,Javascript,Google Cloud Firestore,成功创建文档后,我想重定向到新创建的文档页面。下面是我的代码 db.collection("problems").add({ statement: statement, details: { difficulty: difficulty, type: type, title: title

成功创建文档后,我想重定向到新创建的文档页面。下面是我的代码

db.collection("problems").add({
                statement: statement,
                details: {
                    difficulty: difficulty,
                    type: type,
                    title: title
                },
                tags: tags,
                timestamp: {
                    created: firebase.firestore.Timestamp.now(),
                    modified: firebase.firestore.Timestamp.now()
                }
            })
            .then(function(docRef) {
                console.log("Document written with ID: ", docRef.id);
                var problemID;
                docRef.get()
                .then( (doc) => {
                    if(doc.exists) {
                        console.log(doc.data());
                        console.log(doc.id);
                        problemID = doc.id;
                        window.location.replace("/practice/problemID");
                    }
                })

            })

但这是行不通的。请告诉我哪里错了?

您需要附加ID

window.location.replace(“/practice/”+problemID)


以上代码来自UI或服务器(nodejs)?此代码来自UI
db.collection("problems").add({
                statement: statement,
                details: {
                    difficulty: difficulty,
                    type: type,
                    title: title
                },
                tags: tags,
                timestamp: {
                    created: firebase.firestore.Timestamp.now(),
                    modified: firebase.firestore.Timestamp.now()
                }
            })
            .then(function(docRef) {
                console.log("Document written with ID: ", docRef.id);
                var problemID;
                docRef.get()
                .then( (doc) => {
                    if(doc.exists) {
                        console.log(doc.data());
                        console.log(doc.id);
                        problemID = doc.id;
                        window.location.replace("/practice/"+problemID);
                    }
                })

            })