import wixLocation from 'wix-location' became import wixLocationFrontend from 'wix-location-frontend' a little while ago. They both import and do the same thing.
That said, they can only be used in page code, and won’t work when using routers.
When working with routers, you’ll want to use the data provided in the request to understand the page being navigated to - docs for it here - Wix Router Request Introduction | Velo
The biggest issue is likely the function name. In Wix Routers, the naming convention is prefix_hookName. Since your URL prefix is work, the function must be named work_customizeQuery. If it’s named workRouter_..., it won’t recognize it as the hook and will just skip it.
I also noticed you were trying to match strings like "{Project Name}". The router doesn’t parse those as variables in a string comparison; instead, you should use the request.path array to look at specific segments of the URL.
Here is a cleaned-up version of the code:
import { redirect } from "wix-router";
export function work_customizeQuery(request, route, query) {
console.log("Router running")
const baseURL = request.baseUrl;
const path = request.path; // This is an array of the URL segments after /work/
const category = path[0];
const projectSlug = path[1];
// 1. Handle the SnapMD redirect first
if (category === "product-management" && projectSlug === "virtual-care-management") {
return redirect(`${baseURL}/work/product-management/unique/snapmd`);
}
// 2. Adjust queries based on the category segment (path[0])
if (category === "branding") {
return query.eq("primaryCategory", "Branding");
}
else if (category === "product-management") {
// Double check your collection spelling for "Managment" vs "Management"!
return query.eq("primaryCategory", "Product Managment");
}
else if (category === "creative") {
return query.eq("primaryCategory", "Creative");
}
return query;
}
A few quick tips on this:
Path segments:path[0] is your category (branding, creative, etc.), and path[1] is the specific item slug. This is much more reliable than trying to match the full route string.
Typos: Just a heads up - your code uses "Product Managment" (missing the ‘e’). Make sure that matches correctly!
Hope this helps with the direction I imagine you’ll need to adapt it further to work with your use case!
“Managment” was a typo in my router code and is spelled correctly in the collection.
Unfortunately, this still does not seem to be working. At least, the redirect is not loading the alternate page layout and the query changes do not seem to impact the data in such a way that the next and previous buttons function within only the active “Primary Category”
Here is the code I plugged in (yours with a couple very small adjustments)
import { redirect } from "wix-router";
export function work_customizeQuery(request, route, query) {
console.log("Router running")
const baseURL = request.baseUrl;
const path = request.path; // This is an array of the URL segments after /work/
const category = path[0];
const projectSlug = path[1];
// 1. Handle the SnapMD redirect first
if (category === "product-management" && projectSlug === "virtual-care-management") {
return redirect(`${baseURL}/work/product-management/unique/snapmd`),
query.eq("projectName", "Virtual Care Management");
}
// 2. Adjust queries based on the category segment (path[0])
if (category === "branding") {
return query.eq("primaryCategory", "Branding");
}
else if (category === "product-management") {
return query.eq("primaryCategory", "Product Management");
}
else if (category === "creative") {
return query.eq("primaryCategory", "Creative");
}
return query;
}