CN116595285B - Route generation method, device, computer equipment and storage medium - Google Patents

Route generation method, device, computer equipment and storage medium Download PDF

Info

Publication number
CN116595285B
CN116595285B CN202310888708.4A CN202310888708A CN116595285B CN 116595285 B CN116595285 B CN 116595285B CN 202310888708 A CN202310888708 A CN 202310888708A CN 116595285 B CN116595285 B CN 116595285B
Authority
CN
China
Prior art keywords
component
route
routing
redirection
configuration information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202310888708.4A
Other languages
Chinese (zh)
Other versions
CN116595285A (en
Inventor
梁德金
何俊泽
王颖奇
冯斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Fulin Technology Co Ltd
Original Assignee
Shenzhen Fulin Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Fulin Technology Co Ltd filed Critical Shenzhen Fulin Technology Co Ltd
Priority to CN202310888708.4A priority Critical patent/CN116595285B/en
Publication of CN116595285A publication Critical patent/CN116595285A/en
Application granted granted Critical
Publication of CN116595285B publication Critical patent/CN116595285B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/958Organisation or management of web site content, e.g. publishing, maintaining pages or automatic linking
    • G06F16/986Document structures and storage, e.g. HTML extensions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/954Navigation, e.g. using categorised browsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application belongs to the technical field of software development, and relates to a route generation method, a device, computer equipment and a storage medium, wherein the method comprises the following steps: acquiring an initial file path of a route to be generated; performing conversion operation on the initial file path to obtain route configuration information; performing component generation operation according to the route configuration information to obtain a route component, and loading the route component according to a dynamic loading mode; acquiring redirection routing configuration information, and performing redirection routing component generation operation according to the redirection routing configuration information to obtain a redirection routing component; and wrapping the routing component and the redirection routing component according to the Routes component, and sequentially rendering the routing component and the redirection routing component. The method and the device simplify the process of manually configuring the route, and improve the maintainability and flexibility of codes.

Description

Route generation method, device, computer equipment and storage medium
Technical Field
The present disclosure relates to the field of software development technologies, and in particular, to a route generating method, a device, a computer device, and a storage medium.
Background
In existing systems, there are typically a large number of pages and components.
To implement functions such as skip, navigation, and deep link between pages, a route needs to be manually configured to define a mapping relationship between URLs and pages.
However, the applicant found that when the application program is changed, for example, when a page is newly added, deleted or renamed, the routing configuration needs to be manually updated, which is a tedious and error-prone task, so that the conventional manual routing configuration method has a problem of low fault tolerance.
Disclosure of Invention
An objective of the embodiments of the present application is to provide a route generation method, apparatus, computer device, and storage medium, so as to solve the problem of low fault tolerance in the conventional manual configuration route manner.
In order to solve the above technical problems, the embodiments of the present application provide a route generating method, which adopts the following technical schemes:
acquiring an initial file path of a route to be generated;
performing conversion operation on the initial file path to obtain route configuration information;
performing component generation operation according to the route configuration information to obtain a route component, and loading the route component according to a dynamic loading mode;
Acquiring redirection routing configuration information, and performing redirection routing component generation operation according to the redirection routing configuration information to obtain a redirection routing component;
and wrapping the routing component and the redirection routing component according to the Routes component, and sequentially rendering the routing component and the redirection routing component.
Further, the step of obtaining the initial file path of the route to be generated specifically includes the following steps:
acquiring a file path mode of the initial file path according to the import. Meta. Glob method of Vite;
and acquiring the matched initial file path according to the file path mode.
Further, the step of converting the initial file path to obtain the routing configuration information specifically includes the following steps:
and acquiring a defined getrequests function, and converting the defined getrequests function into a defined routing mode based on the getrequests function to obtain the routing configuration information, wherein the defined routing mode is used for redefining a routing address.
Further, the step of performing component generating operation according to the route configuration information to obtain a route component and loading the route component according to a dynamic loading mode specifically includes the following steps:
Calling a defined getrequest list function, and generating an initial routing component corresponding to the routing configuration information according to the routing configuration information based on the getrequest list function;
traversing the routing configuration information, wherein the routing configuration information comprises N configuration items, and N is an integer greater than or equal to 1;
dynamically loading each initial routing component according to a loadable method, and transmitting an object derived by the input module as a parameter to obtain an intermediate routing component;
and modifying the path of the intermediate routing component into the routing path of the routing configuration information, wherein the element of the intermediate routing component is a dynamically loaded component and can provide a Loading component in Loading.
Further, the step of obtaining the redirection routing configuration information and performing the redirection routing component generating operation according to the redirection routing configuration information to obtain the redirection routing component specifically includes the following steps:
traversing the redirection routing configuration information, wherein the redirection routing configuration information comprises M configuration items, and M is an integer greater than or equal to 1;
and calling a defined getrouting function, and performing Route component generation operation on configuration items of each redirection routing configuration information according to the redirection routing configuration information based on the getrouting function to obtain the redirection routing component.
Further, the step of wrapping the routing component and the redirecting routing component according to the Routes component and sequentially rendering the routing component and the redirecting routing component specifically includes the following steps:
calling a defined AutoRouter component, and wrapping the routing component and the redirection routing component according to the router component based on the AutoRouter component;
the sub-components, dynamically loaded routing components, redirection routing components, and last NoMatch component that matches all paths are rendered in order.
In order to solve the above technical problems, the embodiments of the present application further provide a route generating device, which adopts the following technical scheme:
the path acquisition module is used for acquiring an initial file path of the route to be generated;
the conversion module is used for carrying out conversion operation on the initial file path to obtain route configuration information;
the component generating module is used for carrying out component generating operation according to the route configuration information to obtain a route component, and loading the route component according to a dynamic loading mode;
the redirection routing component generation module is used for acquiring redirection routing configuration information, and carrying out redirection routing component generation operation according to the redirection routing configuration information to obtain a redirection routing component;
And the route generation module is used for carrying out wrapping operation on the route component and the redirection route component according to the Routes component and sequentially rendering the route component and the redirection route component.
Further, the path acquisition module includes:
a path mode obtaining sub-module, configured to obtain a file path mode of the initial file path according to an import. Meta. Glob method of Vite;
and the initial file path acquisition sub-module is used for acquiring the matched initial file path according to the file path mode.
In order to solve the above technical problems, the embodiments of the present application further provide a computer device, which adopts the following technical schemes:
comprising a memory having stored therein computer readable instructions which when executed by a processor implement the steps of the route generation method as described above.
In order to solve the above technical problems, embodiments of the present application further provide a computer readable storage medium, which adopts the following technical solutions:
the computer readable storage medium has stored thereon computer readable instructions which when executed by a processor implement the steps of the route generation method as described above.
The application provides a route generation method, which comprises the following steps: acquiring an initial file path of a route to be generated; performing conversion operation on the initial file path to obtain route configuration information; performing component generation operation according to the route configuration information to obtain a route component, and loading the route component according to a dynamic loading mode; acquiring redirection routing configuration information, and performing redirection routing component generation operation according to the redirection routing configuration information to obtain a redirection routing component; and wrapping the routing component and the redirection routing component according to the Routes component, and sequentially rendering the routing component and the redirection routing component. Compared with the prior art, the method simplifies the process of manually configuring the route by writing some auxiliary functions and components, improves the maintainability and flexibility of codes, and simultaneously, a developer can more conveniently expand and manage the route part of the application by automatically generating the route, thereby improving the development efficiency; the performance and user experience of the application can be optimized through the dynamic loading component and the support redirection function; the application gives consideration to development efficiency, maintainability, application performance and the like, so that a developer can manage and expand the routing part of the application more conveniently.
Drawings
For a clearer description of the solution in the present application, a brief description will be given below of the drawings that are needed in the description of the embodiments of the present application, it being obvious that the drawings in the following description are some embodiments of the present application, and that other drawings may be obtained from these drawings without inventive effort for a person of ordinary skill in the art.
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
fig. 2 is a flowchart of an implementation of a route generation method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a route generating device according to a second embodiment of the present application;
FIG. 4 is a schematic structural diagram of one embodiment of a computer device according to the present application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the applications herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having" and any variations thereof in the description and claims of the present application and in the description of the figures above are intended to cover non-exclusive inclusions. The terms first, second and the like in the description and in the claims or in the above-described figures, are used for distinguishing between different objects and not necessarily for describing a sequential or chronological order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the present application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
In order to better understand the technical solutions of the present application, the following description will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings.
As shown in fig. 1, a system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like. Various communication client applications, such as a web browser application, a shopping class application, a search class application, an instant messaging tool, a mailbox client, social platform software, etc., may be installed on the terminal devices 101, 102, 103.
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablet computers, electronic book readers, MP3 players (Moving Picture Experts Group Audio Layer III, dynamic video expert compression standard audio plane 3), MP4 (Moving Picture Experts Group Audio Layer IV, dynamic video expert compression standard audio plane 4) players, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background server providing support for pages displayed on the terminal devices 101, 102, 103.
It should be noted that, the route generating method provided in the embodiments of the present application is generally executed by a server/terminal device, and accordingly, the route generating apparatus is generally disposed in the server/terminal device.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
With continued reference to fig. 2, a flow chart of one embodiment of a route generation method according to the present application is shown. The route generation method comprises the following steps: step S201, step S202, step S203, step S204, step S205, step S206, and step S207.
In step S201, an initial file path of a route to be generated is acquired.
In the embodiment of the application, before the initial file path is acquired, an initialization process is required, specifically, the initialization process needs to introduce necessary dependency libraries and components at the same time, specifically including a act, a Vite, a act Router and the like, wherein the act is a JavaScript library for constructing a user interface, and the application utilizes the act library to construct a front-end application program; the Vite is a front-end development and construction tool, is intended to provide out-of-box configuration, and meanwhile, a plug-in API and a JavaScript API of the Vite bring high expandability and complete type support, and the application dynamically acquires a file path matched with a specified mode by using an import. Meta. Glob method; the React Router is an available route library for the React items, which is available in the present application.
In the embodiment of the application, besides the dependency libraries and components of the React, vite, act Router and the like, loadable, routes components, route components and navigator components are cited, wherein:
vite: dynamically acquiring a file path matching a specified mode by using an import. Meta. Glob method; reaction: constructing a front-end application program by using a reaction library, and realizing a routing function by using the reaction Router library; loadable: dynamic loading of the components is realized through a loadable method, namely, the components are loaded when needed, so that the application performance and the loading speed are improved;
The Routes component: the components in the act Router library are used for wrapping all the routing components and realizing the rendering and matching of the routing;
route component: components in the act Router library that define paths, elements (components), and other attributes of a single route;
navigate component: the components in the act Router library are used for navigation and redirection of pages.
In this embodiment of the present application, the method of obtaining the initial file path may be that a weback import. Meta. Glob method is used, and a designated file path mode'/src/page is imported to obtain the matched file path. The method returns an object, the key is the file path, and the value is the export object of the module.
In the embodiment of the application, the import. Meta. Glob method is to import the matched module by calling the import. Meta. Glob method after defining the routing mode, and the import. Meta. Glob method returns an object, wherein each key is the matched module path, and each value is an asynchronous loading function for dynamically importing the corresponding module.
In step S202, a conversion operation is performed on the initial file path to obtain route configuration information.
In the embodiment of the present application, the conversion operation may be to define a getpaths function, and convert the obtained file paths into route configuration information; traversing the keys of the file path object (file path), processing each key: the route path conversion is from "/src/page/page. Xxx= >/page/page". The specific procedure is as follows:
(1) Removing '/', at the beginning of the path, and removing the first character '/', using the slice (1) method;
(2) Splitting the path character string into arrays by using a split ('/') method;
(3) Removing the last element in the array, namely the suffix part of the file by using a slice (0, -1) method;
(4) Removing a first element in the array, namely a root directory part, by using a shift () method;
(5) Splicing elements in the array into a character string by using a join ('/') method to obtain a routing path;
(6) An object array is returned that contains the routing paths and module export objects.
In step S203, the component generating operation is performed according to the route configuration information, so as to obtain a route component, and the route component is loaded according to the dynamic loading mode.
In the embodiment of the application, the component generating operation may be to define a getoutput list function, and receive an optional Loading component as a parameter. And generating a corresponding Route component according to the Route configuration information. Traversing the route configuration array, and carrying out the following treatment on each configuration item:
(1) Dynamically loading corresponding components by using a loadable method, and exporting objects as parameters by an afferent module;
(2) Returning to a Route component, setting a path as a routing path, setting an element as a dynamically loaded component, and providing a Loading component in Loading.
In step S204, the redirection routing configuration information is obtained, and the redirection routing component generating operation is performed according to the redirection routing configuration information, so as to obtain the redirection routing component.
In an embodiment of the present application, the operation of generating the redirection routing component may be to define a getrouting function, through which the redirection routing configuration array is received as a parameter; traversing the redirection routing configuration array, and carrying out the following treatment on each configuration item:
returning to a Route component, setting the path to redirect the initial path, the element being a navigation component, and redirecting the path to the target path.
In the embodiments of the present application, the redirection routing component mainly redirects various network requests to other locations through various methods. Such as: the user is on the commodity page, the commodity server to be purchased finds that the user is not logged in, the browser jumps to the login page at the moment, and returns to the commodity page after successful login, for example: the user is in the personal center, the password server is modified to find that the user is not logged in, the browser jumps to the login page at the moment, and the user returns to the personal center page after logging in successfully.
In the embodiment of the present application, the route redirection needs to be completed using a keyword redirect routing hook function Q (to, from, next).
In step S205, the routing component and the redirection routing component are wrapped according to the Routes component, and the routing component and the redirection routing component are sequentially rendered.
In the embodiment of the present application, an autoprotter component is defined as an entry component of the entire auto-generated route, and a redirect route configuration, children, loading (component in load), and nomach (unmatched route component) are received as parameters.
All routing components are wrapped using the Routes component.
The sub-components, dynamically loaded routing components, redirection routing components, and last NoMatch component that matches all paths are rendered in order.
In the embodiment of the application, through the steps, the scheme realizes the function of automatically generating the route. The developer can automatically generate the corresponding route configuration by only compiling the file conforming to the specific naming rule and placing the file in the appointed catalogue. The automatic generation mode simplifies the route configuration process and improves the development efficiency.
In an embodiment of the present application, a route generating method is provided, including: acquiring an initial file path of a route to be generated; performing conversion operation on the initial file path to obtain route configuration information; performing component generation operation according to the route configuration information to obtain a route component, and loading the route component according to a dynamic loading mode; acquiring redirection routing configuration information, and performing redirection routing component generation operation according to the redirection routing configuration information to obtain a redirection routing component; and wrapping the routing component and the redirection routing component according to the Routes component, and sequentially rendering the routing component and the redirection routing component. Compared with the prior art, the method simplifies the process of manually configuring the route by writing some auxiliary functions and components, improves the maintainability and flexibility of codes, and simultaneously, a developer can more conveniently expand and manage the route part of the application by automatically generating the route, thereby improving the development efficiency; the performance and user experience of the application can be optimized through the dynamic loading component and the support redirection function; the application gives consideration to development efficiency, maintainability, application performance and the like, so that a developer can manage and expand the routing part of the application more conveniently.
In some optional implementations of the present embodiment, step S201 specifically includes the following steps:
acquiring a file path mode of an incoming initial file path according to an import. Meta. Glob method of Vite, wherein the file path mode is/src/page;
and acquiring a matched initial file path according to the file path mode.
In some optional implementations of the present embodiment, step S202 specifically includes the following steps:
and obtaining a defined getrequests function, and converting the initial file path into a defined route path based on the getrequests function to obtain the route configuration information, wherein the defined route path is used for redefining a route address, and specifically, the route configuration information is obtained by converting/src/page.
In the embodiment of the application, the getrequests function converts the acquired file path into an array of the routing configuration object, and returns the array.
In some optional implementations of this embodiment, step SS203 specifically includes the following steps:
calling a defined getrequest list function, and generating an initial routing component corresponding to the routing configuration information according to the routing configuration information based on the getrequest list function;
traversing route configuration information, wherein the route configuration information comprises N configuration items, and N is an integer greater than or equal to 1;
Dynamically loading each initial routing component according to a loadable method, and transmitting an object derived by the input module as a parameter to obtain an intermediate routing component;
the path of the intermediate routing component is modified into the routing path of the routing configuration information, and the elements of the intermediate routing component are dynamically loaded components and can provide Loading components in the Loading process.
In the embodiment of the application, the getrequest list function generates a corresponding Route component according to the Route configuration array, and loads the component by using a dynamic loading (loadable) mode. If a Loading component is provided, the contents of the Loading component are displayed during the component Loading process.
In some optional implementations of the present embodiment, step S204 specifically includes the following steps:
traversing redirection route configuration information, wherein the redirection route configuration information comprises M configuration items, and M is an integer greater than or equal to 1;
calling a defined getrouting function, and performing Route component generating operation on configuration items of each redirection routing configuration information according to the redirection routing configuration information based on the getrouting function to obtain a redirection routing component.
In the embodiment of the application, the getRedirect function generates a corresponding Route component according to the provided redirect routing configuration, and achieves the function of page redirection.
In some optional implementations of the present embodiment, step S205 specifically includes the following steps:
calling a defined AutoRouter component, and wrapping a routing component and a redirection routing component according to the router component based on the AutoRouter component;
the sub-components, dynamically loaded routing components, redirection routing components, and last NoMatch component that matches all paths are rendered in order.
In the embodiment of the application, the AutoRouter component is a function component that accepts redirectRoutes, children, loading and NoMatch as parameters. It wraps all routing components with Routes components and renders sub-components, dynamically loaded routing components, redirection routing components, and last nomach component matching all paths in order.
In summary, the present application implements the front-end auto-generation routing function based on act and Vite. The Vite supports the dynamic import of multiple modules from the file system using a special import. Meta. Glob function, obtains the file path by reading the file under a specified directory, and uses its information as routing configuration information. Specifically, it obtains all files prefixed by page in the/src directory and its subdirectories by specifying the pattern '/src/page'. Then, it converts the obtained file path into route configuration information including the route path and the corresponding component loader. These routing configurations are then rendered by the reactive routing component (Router) and dynamic loading (loadable), enabling automated route generation. The design can simplify the process of manually creating and managing the route, and improves the development efficiency.
The embodiment of the application can acquire and process the related data based on the artificial intelligence technology. Among these, artificial intelligence (Artificial Intelligence, AI) is the theory, method, technique and application system that uses a digital computer or a digital computer-controlled machine to simulate, extend and extend human intelligence, sense the environment, acquire knowledge and use knowledge to obtain optimal results.
Artificial intelligence infrastructure technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and other directions. Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by computer readable instructions stored in a computer readable storage medium that, when executed, may comprise the steps of the embodiments of the methods described above. The storage medium may be a nonvolatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a random access Memory (Random Access Memory, RAM).
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited in order and may be performed in other orders, unless explicitly stated herein. Moreover, at least some of the steps in the flowcharts of the figures may include a plurality of sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, the order of their execution not necessarily being sequential, but may be performed in turn or alternately with other steps or at least a portion of the other steps or stages.
Examples
With further reference to fig. 3, as an implementation of the method shown in fig. 2, the present application provides an embodiment of a route generating device, where an embodiment of the device corresponds to the embodiment of the method shown in fig. 2, and the device may be specifically applied to various electronic devices.
As shown in fig. 3, the route generation device 200 of the present embodiment includes: an acquisition module 401, an identification module 402, a calculation module 403, a training module 404, and a processing module 405. Wherein:
A path obtaining module 210, configured to obtain an initial file path of a route to be generated;
the conversion module 220 is configured to perform a conversion operation on the initial file path to obtain route configuration information;
the component generating module 230 is configured to perform component generating operation according to the route configuration information, obtain a route component, and load the route component according to a dynamic loading manner;
the redirection routing component generating module 240 is configured to obtain redirection routing configuration information, and perform a redirection routing component generating operation according to the redirection routing configuration information to obtain a redirection routing component;
the route generation module 250 is configured to perform a wrapping operation on the route component and the redirect route component according to the route component, and sequentially render the route component and the redirect route component.
In this embodiment, a route generating device 200 is provided, including: a path obtaining module 210, configured to obtain an initial file path of a route to be generated; the conversion module 220 is configured to perform a conversion operation on the initial file path to obtain route configuration information; the component generating module 230 is configured to perform component generating operation according to the route configuration information, obtain a route component, and load the route component according to a dynamic loading manner; the redirection routing component generating module 240 is configured to obtain redirection routing configuration information, and perform a redirection routing component generating operation according to the redirection routing configuration information to obtain a redirection routing component; the route generation module 250 is configured to perform a wrapping operation on the route component and the redirect route component according to the route component, and sequentially render the route component and the redirect route component. Compared with the prior art, the method simplifies the process of manually configuring the route by writing some auxiliary functions and components, improves the maintainability and flexibility of codes, and simultaneously, a developer can more conveniently expand and manage the route part of the application by automatically generating the route, thereby improving the development efficiency; the performance and user experience of the application can be optimized through the dynamic loading component and the support redirection function; the application gives consideration to development efficiency, maintainability, application performance and the like, so that a developer can manage and expand the routing part of the application more conveniently.
In some optional implementations of the present embodiment, the path obtaining module 210 includes: the path mode acquisition sub-module and the initial file path acquisition sub-module, wherein:
the path mode obtaining sub-module is used for obtaining a file path mode of an incoming initial file path according to an import. Meta. Glob method of Vite, wherein the file path mode is/src/page;
and the initial file path acquisition sub-module is used for acquiring the matched initial file path according to the file path mode.
In some optional implementations of this embodiment, the conversion module 220 includes: a conversion sub-module, wherein:
and the conversion sub-module is used for acquiring a defined getrequests function, converting the initial file path into a defined route path based on the getrequests function, and obtaining the route configuration information, wherein the defined route path is used for redefining a route address, namely, converting the page into the page.
In some optional implementations of this embodiment, the component generating module 230 includes: the method comprises the steps of an initial component generation sub-module, a route configuration information traversing sub-module, an intermediate component acquisition sub-module and a component generation sub-module, wherein:
An initial component generating sub-module, which is used for calling a defined getrequest list function and generating an initial routing component corresponding to the routing configuration information according to the routing configuration information based on the getrequest list function;
the routing configuration information traversing sub-module is used for traversing the routing configuration information, wherein the routing configuration information comprises N configuration items, and N is an integer greater than or equal to 1;
the intermediate component acquisition sub-module is used for dynamically loading each initial routing component according to a loadable method, and transmitting an object derived by the input module as a parameter to obtain an intermediate routing component;
the component generating sub-module is used for modifying the path of the intermediate routing component into the routing path of the routing configuration information, wherein the element of the intermediate routing component is a dynamically loaded component and can provide a Loading component in Loading.
In some optional implementations of this embodiment, the redirection routing component generation module 240 includes: the redirection routing configuration information traversal sub-module and the redirection routing component generation sub-module, wherein:
the redirection route configuration information traversing sub-module is used for traversing the redirection route configuration information, wherein the redirection route configuration information comprises M configuration items, and M is an integer greater than or equal to 1;
And the redirection routing component generation sub-module is used for calling a defined getrouting function, and carrying out Route component generation operation on the configuration item of each redirection routing configuration information according to the redirection routing configuration information based on the getrouting function to obtain the redirection routing component.
In some optional implementations of this embodiment, the route generation module 250 includes: the component parcel submodule and the component rendering submodule, wherein:
the assembly parcel sub-module is used for calling the defined AutoRouter assembly, and parcel the routing assembly and redirecting the routing assembly according to the router assembly based on the AutoRouter assembly;
the component rendering sub-module is used for sequentially rendering the sub-component, the dynamically loaded routing component, the redirection routing component and the last NoMatch component matched with all paths.
In order to solve the technical problems, the embodiment of the application also provides computer equipment. Referring specifically to fig. 4, fig. 4 is a basic structural block diagram of a computer device according to the present embodiment.
The computer device 6 comprises a memory 61, a processor 62, a network interface 63 communicatively connected to each other via a system bus. It is noted that only computer device 6 having components 61-63 is shown in the figures, but it should be understood that not all of the illustrated components are required to be implemented and that more or fewer components may be implemented instead. It will be appreciated by those skilled in the art that the computer device herein is a device capable of automatically performing numerical calculations and/or information processing in accordance with predetermined or stored instructions, the hardware of which includes, but is not limited to, microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASICs), programmable gate arrays (fields-Programmable Gate Array, FPGAs), digital processors (Digital Signal Processor, DSPs), embedded devices, etc.
The computer equipment can be a desktop computer, a notebook computer, a palm computer, a cloud server and other computing equipment. The computer equipment can perform man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch pad or voice control equipment and the like.
The memory 61 includes at least one type of readable storage media including flash memory, hard disk, multimedia card, card memory (e.g., SD or DX memory, etc.), random Access Memory (RAM), static Random Access Memory (SRAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), programmable Read Only Memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the storage 61 may be an internal storage unit of the computer device 6, such as a hard disk or a memory of the computer device 6. In other embodiments, the memory 61 may also be an external storage device of the computer device 6, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card (Flash Card) or the like, which are provided on the computer device 6. Of course, the memory 61 may also comprise both an internal memory unit of the computer device 6 and an external memory device. In this embodiment, the memory 61 is typically used to store an operating system and various application software installed on the computer device 6, such as computer readable instructions of a route generation method. Further, the memory 61 may be used to temporarily store various types of data that have been output or are to be output.
The processor 62 may be a central processing unit (Central Processing Unit, CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments. The processor 62 is typically used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is configured to execute computer readable instructions stored in the memory 61 or process data, such as computer readable instructions for executing the route generating method.
The network interface 63 may comprise a wireless network interface or a wired network interface, which network interface 63 is typically used for establishing a communication connection between the computer device 6 and other electronic devices.
According to the computer equipment, by writing the auxiliary functions and the components, the process of manually configuring the route is simplified, the maintainability and the flexibility of codes are improved, meanwhile, by automatically generating the route, a developer can more conveniently expand and manage the route part of the application, and the development efficiency is improved; the performance and user experience of the application can be optimized through the dynamic loading component and the support redirection function; the application gives consideration to development efficiency, maintainability, application performance and the like, so that a developer can manage and expand the routing part of the application more conveniently.
The present application also provides another embodiment, namely, a computer-readable storage medium storing computer-readable instructions executable by at least one processor to cause the at least one processor to perform the steps of the route generation method as described above.
The computer readable storage medium simplifies the process of manually configuring the route by writing some auxiliary functions and components, improves the maintainability and flexibility of codes, and simultaneously, a developer can more conveniently expand and manage the route part of the application by automatically generating the route, thereby improving the development efficiency; the performance and user experience of the application can be optimized through the dynamic loading component and the support redirection function; the application gives consideration to development efficiency, maintainability, application performance and the like, so that a developer can manage and expand the routing part of the application more conveniently.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk), comprising several instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method described in the embodiments of the present application.
It is apparent that the embodiments described above are only some embodiments of the present application, but not all embodiments, the preferred embodiments of the present application are given in the drawings, but not limiting the patent scope of the present application. This application may be embodied in many different forms, but rather, embodiments are provided in order to provide a more thorough understanding of the present disclosure. Although the present application has been described in detail with reference to the foregoing embodiments, it will be apparent to those skilled in the art that modifications may be made to the embodiments described in the foregoing, or equivalents may be substituted for elements thereof. All equivalent structures made by the specification and the drawings of the application are directly or indirectly applied to other related technical fields, and are also within the protection scope of the application.

Claims (7)

1. A route generation method, comprising the steps of:
acquiring an initial file path of a route to be generated;
performing conversion operation on the initial file path to obtain route configuration information;
performing component generation operation according to the route configuration information to obtain a route component, and loading the route component according to a dynamic loading mode, wherein the dynamic loading mode loads the route component based on a loadable component;
Acquiring redirection routing configuration information, and performing redirection routing component generation operation according to the redirection routing configuration information to obtain a redirection routing component;
wrapping the routing component and the redirection routing component according to the Routes component, and sequentially rendering the routing component and the redirection routing component;
before the step of obtaining the initial file path of the route to be generated, the method further comprises the following steps:
introducing a real dependency library, a Vite component and a real Router routing library to perform initialization processing, wherein the Vite component dynamically acquires a file path matched with a specified mode by using an import. Meta. Glob method;
the step of converting the initial file path to obtain the route configuration information specifically comprises the following steps:
acquiring a defined getrequests function, and converting the initial file path into a defined route path based on the getrequests function to obtain the route configuration information, wherein the defined route path is used for redefining a route address;
the step of converting the initial file path into a defined routing path includes the steps of:
removing '/', at the beginning of the path, and removing the first character '/', using the slice (1) method;
Splitting the path character string into arrays by using a split ('/') method;
removing the last element in the array, namely the suffix part of the file by using a slice (0, -1) method;
removing a first element in the array, namely a root directory part, by using a shift () method;
splicing elements in the array into a character string by using a join ('/') method to obtain a routing path;
returning an object array comprising routing paths and module export objects;
the step of obtaining the redirection routing configuration information, and performing the generation operation of the redirection routing component according to the redirection routing configuration information to obtain the redirection routing component specifically comprises the following steps:
traversing the redirection routing configuration information, wherein the redirection routing configuration information comprises M configuration items, and M is an integer greater than or equal to 1;
calling a defined getrouting function, and performing Route component generation operation on configuration items of each redirection routing configuration information according to the redirection routing configuration information based on the getrouting function to obtain the redirection routing components;
the step of wrapping the routing component and the redirecting routing component according to the Routes component and sequentially rendering the routing component and the redirecting routing component specifically comprises the following steps:
Calling a defined AutoRouter component, and wrapping the routing component and the redirection routing component according to the router component based on the AutoRouter component;
the sub-components, dynamically loaded routing components, redirection routing components, and last NoMatch component that matches all paths are rendered in order.
2. The route generation method according to claim 1, wherein the step of obtaining the initial file path of the route to be generated comprises the steps of:
acquiring a file path mode of the initial file path according to the import. Meta. Glob method of Vite;
and acquiring the matched initial file path according to the file path mode.
3. The route generating method according to claim 1, wherein the step of performing component generating operation according to the route configuration information to obtain a route component and loading the route component according to a dynamic loading manner specifically comprises the following steps:
calling a defined getrequest list function, and generating an initial routing component corresponding to the routing configuration information according to the routing configuration information based on the getrequest list function;
Traversing the routing configuration information, wherein the routing configuration information comprises N configuration items, and N is an integer greater than or equal to 1;
dynamically loading each initial routing component according to a loadable method, and transmitting an object derived by the input module as a parameter to obtain an intermediate routing component;
and modifying the path of the intermediate routing component into the routing path of the routing configuration information, wherein the element of the intermediate routing component is a dynamically loaded component and can provide a Loading component in Loading.
4. A route generation device, comprising:
the path acquisition module is used for acquiring an initial file path of the route to be generated;
the conversion module is used for carrying out conversion operation on the initial file path to obtain route configuration information;
the component generating module is used for carrying out component generating operation according to the route configuration information to obtain a route component and loading the route component according to a dynamic loading mode, wherein the dynamic loading mode loads the route component based on a loadable component;
the redirection routing component generation module is used for acquiring redirection routing configuration information, and carrying out redirection routing component generation operation according to the redirection routing configuration information to obtain a redirection routing component;
The route generation module is used for carrying out wrapping operation on the route component and the redirection route component according to the Routes component and sequentially rendering the route component and the redirection route component;
the apparatus further comprises:
the initialization module is used for introducing a real dependency library, a Vite component and a real Router routing library to perform initialization processing, wherein the Vite component dynamically acquires a file path matched with a specified mode by using an import. Meta. Glob method;
the conversion module includes:
the conversion sub-module is used for acquiring a defined getrequests function, converting the initial file path into a defined route path based on the getrequests function, and obtaining the route configuration information, wherein the defined route path is used for redefining a route address;
the conversion submodule is further used for removing '/', at the beginning of a path, of a first character by using a slice (1) method;
the conversion submodule is also used for splitting the path character string into an array by using a split ('/') method;
the conversion sub-module is further used for removing the last element in the array, namely the suffix part of the file, by using a slice (0, -1) method;
the conversion submodule is further used for removing a first element in the array, namely a root directory part, by using a shift () method;
The conversion submodule is also used for splicing elements in the array into a character string by using a join ('/') method to obtain a routing path;
the conversion sub-module is also used for returning an object array containing routing paths and module export objects;
the redirection routing component generation module specifically comprises: the redirection routing configuration information traversal sub-module and the redirection routing component generation sub-module, wherein:
the redirection route configuration information traversing submodule is used for traversing the redirection route configuration information, wherein the redirection route configuration information comprises M configuration items, and M is an integer greater than or equal to 1;
a redirection routing component generating sub-module, configured to call a defined getrouting function, and perform Route component generating operation on a configuration item of each redirection routing configuration information according to the redirection routing configuration information based on the getrouting function, so as to obtain the redirection routing component;
the route generation module specifically comprises: the component parcel submodule and the component rendering submodule, wherein:
the module package sub-module is used for calling a defined AutoRouter module, and packaging the routing module and the redirection routing module according to the router module based on the AutoRouter module;
The component rendering sub-module is used for sequentially rendering the sub-component, the dynamically loaded routing component, the redirection routing component and the last NoMatch component matched with all paths.
5. The route generation device according to claim 4, wherein the path acquisition module comprises:
a path mode obtaining sub-module, configured to obtain a file path mode of the initial file path according to an import. Meta. Glob method of Vite;
and the initial file path acquisition sub-module is used for acquiring the matched initial file path according to the file path mode.
6. A computer device comprising a memory having stored therein computer readable instructions which when executed by a processor implement the steps of the route generation method of any of claims 1 to 3.
7. A computer readable storage medium having stored thereon computer readable instructions which when executed by a processor implement the steps of the route generation method of any of claims 1 to 3.
CN202310888708.4A 2023-07-19 2023-07-19 Route generation method, device, computer equipment and storage medium Active CN116595285B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310888708.4A CN116595285B (en) 2023-07-19 2023-07-19 Route generation method, device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310888708.4A CN116595285B (en) 2023-07-19 2023-07-19 Route generation method, device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN116595285A CN116595285A (en) 2023-08-15
CN116595285B true CN116595285B (en) 2024-04-16

Family

ID=87594216

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310888708.4A Active CN116595285B (en) 2023-07-19 2023-07-19 Route generation method, device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116595285B (en)

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101918926A (en) * 2007-10-24 2010-12-15 乔纳森·彼得·多伊奇 Various methods and apparatuses for accessing networked devices without accessible addresses via virtual IP addresses
CN108390773A (en) * 2018-02-02 2018-08-10 上海汉得信息技术股份有限公司 A kind of method and apparatus of dynamic routing for scaffold
CN110647320A (en) * 2019-08-14 2020-01-03 平安普惠企业管理有限公司 Project framework construction method and device, computer equipment and storage medium
CN111737032A (en) * 2020-07-27 2020-10-02 腾讯科技(深圳)有限公司 Subprogram running method and device based on microkernel system and electronic equipment
CN111857810A (en) * 2020-07-30 2020-10-30 上海妙一生物科技有限公司 Front-end development file creating method and device and electronic equipment
CN111949351A (en) * 2020-08-12 2020-11-17 深圳前海微众银行股份有限公司 Page rendering method, device, equipment and computer readable storage medium
WO2021184824A1 (en) * 2020-03-18 2021-09-23 平安科技(深圳)有限公司 Application program interface gateway based method for separating front and back ends and related device
CN114268538A (en) * 2021-12-08 2022-04-01 马上消费金融股份有限公司 Configuration method and device of front-end route
CN114385935A (en) * 2021-12-02 2022-04-22 天翼电子商务有限公司 Dynamic routing system of service client
CN115733685A (en) * 2022-11-15 2023-03-03 深圳复临科技有限公司 Web session authentication management method and device, computer equipment and storage medium
CN116126330A (en) * 2023-02-14 2023-05-16 深圳依时货拉拉科技有限公司 Access request processing method, device, computer equipment and storage medium

Family Cites Families (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100438682C (en) * 2004-05-14 2008-11-26 华为技术有限公司 Method of dynamic allocating home address remotely for mobile IPv6 node
US9967309B2 (en) * 2014-10-06 2018-05-08 Microsoft Technology Licensing, Llc Dynamic loading of routes in a single-page application
US10129142B2 (en) * 2015-08-11 2018-11-13 Nicira, Inc. Route configuration for logical router
CN110650091B (en) * 2019-08-14 2022-08-02 平安普惠企业管理有限公司 Routing configuration information processing method and device, computer equipment and storage medium
CN110581890B (en) * 2019-09-10 2022-02-22 中国建设银行股份有限公司 Routing method and device for service request
CN111880859A (en) * 2020-07-24 2020-11-03 随身云(南京)信息技术有限公司 Plug-in for automatically generating routing file and method thereof
CN112230927A (en) * 2020-09-17 2021-01-15 贝壳技术有限公司 File redirection method, code loading control method and device
US11916729B2 (en) * 2021-03-12 2024-02-27 Edgio, Inc. Automated configuration of a content delivery network
CN113268260A (en) * 2021-06-07 2021-08-17 京东科技控股股份有限公司 Routing method and device for web front end
CN113805884A (en) * 2021-08-09 2021-12-17 浪潮软件股份有限公司 Configurable front-end development method
CN113918263B (en) * 2021-11-11 2023-09-05 盐城天眼察微科技有限公司 Virtual routing method, device and equipment of view component and computer storage medium
CN114625437A (en) * 2022-03-04 2022-06-14 中国—东盟信息港股份有限公司 Automatic loading method for front-end application configuration
CN114707086A (en) * 2022-03-11 2022-07-05 杭州未名信科科技有限公司 Route generation method and system
CN116225565A (en) * 2023-01-09 2023-06-06 北京达佳互联信息技术有限公司 Method and device for generating route configuration file

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101918926A (en) * 2007-10-24 2010-12-15 乔纳森·彼得·多伊奇 Various methods and apparatuses for accessing networked devices without accessible addresses via virtual IP addresses
CN108390773A (en) * 2018-02-02 2018-08-10 上海汉得信息技术股份有限公司 A kind of method and apparatus of dynamic routing for scaffold
CN110647320A (en) * 2019-08-14 2020-01-03 平安普惠企业管理有限公司 Project framework construction method and device, computer equipment and storage medium
WO2021184824A1 (en) * 2020-03-18 2021-09-23 平安科技(深圳)有限公司 Application program interface gateway based method for separating front and back ends and related device
CN111737032A (en) * 2020-07-27 2020-10-02 腾讯科技(深圳)有限公司 Subprogram running method and device based on microkernel system and electronic equipment
CN111857810A (en) * 2020-07-30 2020-10-30 上海妙一生物科技有限公司 Front-end development file creating method and device and electronic equipment
CN111949351A (en) * 2020-08-12 2020-11-17 深圳前海微众银行股份有限公司 Page rendering method, device, equipment and computer readable storage medium
WO2022033055A1 (en) * 2020-08-12 2022-02-17 深圳前海微众银行股份有限公司 Page rendering method, apparatus, and device, and computer readable storage medium
CN114385935A (en) * 2021-12-02 2022-04-22 天翼电子商务有限公司 Dynamic routing system of service client
CN114268538A (en) * 2021-12-08 2022-04-01 马上消费金融股份有限公司 Configuration method and device of front-end route
CN115733685A (en) * 2022-11-15 2023-03-03 深圳复临科技有限公司 Web session authentication management method and device, computer equipment and storage medium
CN116126330A (en) * 2023-02-14 2023-05-16 深圳依时货拉拉科技有限公司 Access request processing method, device, computer equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于Laravel框架的RESTful API构建;陈显军;耿强;纪洲鹏;湛永松;;信息与电脑(理论版)(第15期);全文 *

Also Published As

Publication number Publication date
CN116595285A (en) 2023-08-15

Similar Documents

Publication Publication Date Title
US20170206188A1 (en) Manipulation of an ajax tree presentation
WO2014204987A1 (en) Method and apparatus for customized software development kit (sdk) generation
CN107250981A (en) Route dynamic load in single page application
CN113536185B (en) Application page loading method, storage medium and related equipment
US11023558B1 (en) Executing functions on-demand on a server utilizing web browsers
CN112416458A (en) Preloading method and device based on ReactNative, computer equipment and storage medium
CN111158750A (en) Unity-based game installation package packaging method and device
CN110851211A (en) Method, apparatus, electronic device, and medium for displaying application information
CN116595285B (en) Route generation method, device, computer equipment and storage medium
CN111581578B (en) Interface request processing method and device
CN113391813A (en) Program compiling method and device, storage medium and electronic equipment
CN114070879B (en) Data collector control method and device and related equipment
CN112925573B (en) Method, device, equipment and computer readable medium for loading web page
CN112445517B (en) Inlet file generation method, device, electronic equipment and computer readable medium
CN112256326B (en) Information processing method, device, equipment and storage medium
CN114675813A (en) Template grammar unifying method and device, computer equipment and storage medium
CN115578050A (en) Approval progress identification method and device, computer equipment and storage medium
CN114185811A (en) Test method, test device, storage medium and electronic equipment
CN117591190A (en) Application data loading optimization method, device, equipment and storage medium thereof
CN117271321A (en) Service automation test method, system, computer equipment and storage medium
CN117290019A (en) Interface calling method and device, computer equipment and storage medium
CN117972256A (en) Linkage form generation method and device, electronic equipment and medium
CN117499270A (en) Flow processing method and device, computer equipment and storage medium
CN117193880A (en) Code loading method, device and equipment of application program and storage medium
CN114842097A (en) Method for converting picture format and related equipment thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant