Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After setting it according to the document, "redirect(/url)" in the action file is not useful, what is the reason? #2264

Open
czw333221 opened this issue Mar 5, 2024 · 1 comment

Comments

@czw333221
Copy link

czw333221 commented Mar 5, 2024

Directory structure:
src/
├── app/
│ └──actions.ts
next-i18next.config.js
next.config.js

//next-i18next.config.js
/**

  • @type {import('next-i18next').UserConfig}
    */
    const path = require('path');
    module.exports = {
    i18n: {
    defaultLocale: 'zh',
    locales: ['en', 'zh'],
    },
    };

//next.config.js
const { withStoreConfig } = require("./store-config")
const store = require("./store.config.json")

/** @type {import('next').NextConfig} */
const { i18n } = require('./next-i18next.config');

/**

  • @type {import('next').NextConfig}
    */
    const nextConfig = withStoreConfig({
    // i18n,
    features: store.features,
    reactStrictMode: true,
    images: {
    remotePatterns: [
    {
    protocol: "http",
    hostname: "localhost",
    },
    {
    protocol: "https",
    hostname: "medusa-public-images.s3.eu-west-1.amazonaws.com",
    },
    {
    protocol: "https",
    hostname: "medusa-server-testing.s3.amazonaws.com",
    },
    {
    protocol: "https",
    hostname: "medusa-server-testing.s3.us-east-1.amazonaws.com",
    },
    ],
    },
    })

console.log("next.config.js", JSON.stringify(module.exports, null, 2))

module.exports = nextConfig

//actions.ts
"use server"

import { revalidateTag } from "next/cache"
import { cookies } from "next/headers"
import { redirect } from "next/navigation"

import { getRegion, updateCart } from "@lib/data"

/**

  • Updates the countrycode param and revalidates the regions cache
  • @param regionId
  • @param countryCode
    */
    export async function updateRegion(countryCode: string, currentPath: string) {
    const cartId = cookies().get("_medusa_cart_id")?.value
    const region = await getRegion(countryCode)

if (!region) {
return null
}

try {
if (cartId) {
await updateCart(cartId, { region_id: region.id })
revalidateTag("cart")
}

revalidateTag("regions")
revalidateTag("products")

} catch (e) {
return "Error updating region"
}
console.log("1111")
redirect(/${countryCode}${currentPath})
}

export async function resetOnboardingState(orderId: string) {
cookies().set("_medusa_onboarding", "false", { maxAge: -1 })
redirect(http://localhost:7001/a/orders/${orderId})
}

The expected result should be yarn dev running and automatically jumping to http://localhost:8000/zh after opening http://localhost:8000

@adrai
Copy link
Member

adrai commented Mar 6, 2024

Next.js has it's own language detection... beside that, I don't know exactly what you mean...
Please do not just paste code snippets but create a minimal reproducible example repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants