Umijs uses convention routing to generate model into the route.

routing problems when building applications using umi.js+dva.js

when building a project containing dva.js according to umi.js "s documentation, a route file automatically generated by a convention route will also generate a route entry from the dva.js "s model file

related codes

pages structure
+pages
    -index.js
    -model.js
automatically generated routes
routes: [
    { path: "/", component: "./pages/index.js" },
    { path: "/model", component: "./pages/model.js" }
]

as described in the document, model automatically registers by name when using dva.js. The rules are as follows:

  • src/models/**/*.js is global model
  • src/pages/**/models/**/*.js is page model
  • global model full load, page model load on demand on production, full load on development
  • page model is the file models/**/*.js under the path where page js resides
  • page model looks up. For example, page js is pages/a/b.js , his page model is pages/a/b/models/**/*.js + pages/a/models/**/*.js , and so on
  • stipulates that model.js is a single file model, to solve the problem that you do not need to build a models directory when there is only one model, and do not look for models/**/*.js if you have model.js.
When

is registered as a model, it should not be built to use this mechanism in the routing, ant admin, and the model.js file or the file under the / models path is not built as a route, so it"s confusing here.

Mar.14,2022

you put your model.js in the models folder, and then configure
routes: {

in your umirc.js.
exclude: [/models\//, /services/, /components/,],

},


the same question, I always route the files in models, how annoying!

clipboard.png

:

clipboard.png

could you tell me how to solve this problem?

Menu