I place this code in a page to redirect
import {redirect} from ‘wix-router’;
export function myRouter_Router(request) {
return redirect(“external_url”, “301”); }
but error shows on the console: Cannot find module ‘wix-router’ in ‘public/pages/p9pk3.js’
I tried to call support but got no help at all. Does anyone know why this issue is happening when ‘wix-router’ is the module name in the corvid documentation as well as this copy being directly from a corvid tutorial article? I am getting very frustrated.
What “corvid tutorial article” are you referencing?
As state in the router API documentation :
The code for both routers and data binding router hooks is defined in the routers.js file that you set up in the Code Files’ Backend section of the Corvid Sidebar .
If you want to redirect from a client page, you can use the wix-location.to() function
https://support.wix.com/en/article/corvid-creating-a-router#add-a-router
Here is the page documentation I was referring to. According to this corvid tutorial article in order to set up the router.js file as you said above you have to import from the ‘wix-router’ module. When I enter that line of code to import I get an error that the ‘wix-router’ module does not exist and as such cannot set up the routers.js file as explained how to do in the corvid article (again as linked above).
Which is infact the same exact article you linked as the set up. Which again is impossible to do when the very first import line statement gives an error.
@marisamyrick In the page documentation that you refer to, it states:
When adding a router:
-
Your router’s router() and sitemap() functions are added in a routers.js file with sample code for a simple routing scenario. The routers.js file is found in the Code Files’s Backend section of the Corvid Sidebar.
Please note, that as stated in the documentation, the wix-router API is not available in frontend code. It can only be used in backend code in a file called routers.js
The import statement is only valid in the routers.js backend file.