LoginSignup
0
0

More than 1 year has passed since last update.

【Vue × Firestore】ページを一つ前に戻る(認証済みユーザー)

Posted at

ページを一つ前に戻る

chat.vue
<router-link :to="`/board/${this.uid}`" class="back-btn">
chat.vue
  created() {

    const currentUser = firebase.auth().currentUser;
    this.uid = currentUser.uid;

    firebase
      .firestore()
      .collection("users")
      .doc(currentUser.uid)
      .get();
}
router.vue
 {
    path: "/board/:uid",
    name: "Board",
    component: Board,
  },

上記では、変数に入れてるが入れずに記述すると下記になります。
このコードでログイン中のuidを取得できます。

chat.vue
 firebase
   .firestore()
   .collection("users")
   .doc(firebase.auth().currentUser.uid)
   .get();

そして、routerで記述したようにPathを"/board/:uidとしているので、
router-linkタグに:to="/board/${this.uid}"としてあげると/boardページに戻ることが出来る。

chat.vue
<router-link :to="`/board/${this.uid}`" class="back-btn">
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0