WO2022033055A1 - Page rendering method, apparatus, and device, and computer readable storage medium - Google Patents

Page rendering method, apparatus, and device, and computer readable storage medium Download PDF

Info

Publication number
WO2022033055A1
WO2022033055A1 PCT/CN2021/085841 CN2021085841W WO2022033055A1 WO 2022033055 A1 WO2022033055 A1 WO 2022033055A1 CN 2021085841 W CN2021085841 W CN 2021085841W WO 2022033055 A1 WO2022033055 A1 WO 2022033055A1
Authority
WO
WIPO (PCT)
Prior art keywords
routing
page
route
sub
matching
Prior art date
Application number
PCT/CN2021/085841
Other languages
French (fr)
Chinese (zh)
Inventor
万纯
林挺
Original Assignee
深圳前海微众银行股份有限公司
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 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2022033055A1 publication Critical patent/WO2022033055A1/en

Links

Classifications

    • 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/451Execution arrangements for user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • 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/957Browsing optimisation, e.g. caching or content distillation
    • 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
    • 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
    • G06F9/4451User profiles; Roaming
    • 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
    • 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

Definitions

  • the present application relates to the technical field of financial technology (Fintech), and in particular, to a page rendering method, apparatus, device, and computer-readable storage medium.
  • server-side rendering also known as back-end rendering
  • server-side rendering can be implemented based on Spring MVC (a java framework).
  • Spring MVC a java framework
  • the browser requests the server, and the server first matches the corresponding route and executes the processor corresponding to the route.
  • HTML HyperText Mark-up Language, hypertext markup language
  • the target usually uses client-side rendering to render the page.
  • Client-side rendering also known as front-end rendering
  • React Router a routing solution
  • page rendering route matching is performed by comparing the path attribute of the Route component with the browser page address. If the page path matches multiple routes, React Router will choose to render the first one.
  • this matching method is not reasonable.
  • the user defines the routes /order/:orderId (order details page) and /order/list (order list page) at the same time, when the user accesses /order/list, the order details page and the order list page can be matched.
  • React Router will render the first order details page that matches, but it's actually more reasonable to render the order list page. Therefore, existing route matching schemes are not accurate.
  • the main purpose of the present application is to provide a page rendering method, apparatus, device and computer-readable storage medium, aiming at solving the problem of inaccurate routing matching scheme in the front-end rendering process.
  • the present application provides a page rendering method, the page rendering method includes:
  • the target component corresponding to the target route is determined according to the routing configuration file, and the target component is loaded to render the target page corresponding to the address of the page to be redirected.
  • the present application also provides a page rendering device, the page rendering device comprising:
  • a first obtaining module configured to obtain the address of the page to be jumped according to the browser page jump request when receiving the browser page jump request
  • a second obtaining module configured to obtain a route matching the address of the page to be jumped from a pre-generated routing configuration file, and obtain a matching routing path of the matching route;
  • a route scoring module for scoring each matched route according to the matching routing path, and determining a target route according to the scoring result
  • a page rendering module configured to determine a target component corresponding to the target route according to the routing configuration file, and load the target component to render a target page corresponding to the address of the page to be jumped.
  • the present application also provides a page rendering device, the page rendering device includes: a memory, a processor, and a page rendering program stored in the memory and running on the processor, When the page rendering program is executed by the processor, the steps of the above-mentioned page rendering method are implemented.
  • the present application also provides a computer-readable storage medium, where a page rendering program is stored on the computer-readable storage medium, and when the page rendering program is executed by a processor, the above-mentioned page rendering is realized steps of the method.
  • the present application provides a page rendering method, apparatus, device and computer-readable storage medium.
  • a browser page jump request When a browser page jump request is received, the address of the page to be jumped is obtained according to the browser page jump request; Obtain the route that matches the address of the page to be jumped from the generated routing configuration file, and obtain the matching routing path of the matching route; score each matching route according to the matching routing path, and The scoring result determines a target route; further, a target component corresponding to the target route is determined according to the routing configuration file, and the target component is loaded to render the target page corresponding to the address of the page to be redirected.
  • a matching route is obtained through a pre-generated routing configuration file, and then the matching route is scored to determine the target route, and then the target component corresponding to the target route is loaded to realize page rendering.
  • FIG. 1 is a schematic diagram of the device structure of the hardware operating environment involved in the solution of the embodiment of the present application;
  • FIG. 2 is a schematic flowchart of a first embodiment of a page rendering method of the present application
  • FIG. 3 is a schematic diagram of functional modules of the first embodiment of the page rendering apparatus of the present application.
  • FIG. 1 is a schematic diagram of a device structure of a hardware operating environment involved in the solution of an embodiment of the present application.
  • the page rendering device in this embodiment of the present application may be a smartphone, or a PC (Personal Computer, personal computer), tablet computer, portable computer and other terminal equipment.
  • PC Personal Computer, personal computer
  • tablet computer Portable computer and other terminal equipment.
  • the page rendering device may include: a processor 1001 , such as a CPU, a communication bus 1002 , a user interface 1003 , a network interface 1004 , and a memory 1005 .
  • the communication bus 1002 is used to realize the connection and communication between these components.
  • the user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
  • the network interface 1004 may include a standard wired interface and a wireless interface (eg, a Wi-Fi interface).
  • the memory 1005 may be high-speed RAM memory, or may be non-volatile memory, such as disk memory.
  • the memory 1005 may also be a storage device independent of the aforementioned processor 1001 .
  • the structure of the page rendering device shown in FIG. 1 does not constitute a limitation to the page rendering device, and may include more or less components than the one shown, or combine some components, or different components layout.
  • the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module and a page rendering program.
  • the network interface 1004 is mainly used to connect to the background server and perform data communication with the background server; the user interface 1003 is mainly used to connect to the client and perform data communication with the client; and the processor 1001 can be used for
  • the page rendering program stored in the memory 1005 is called, and each step of the following page rendering method is executed.
  • the present application provides a page rendering method.
  • FIG. 2 is a schematic flowchart of a first embodiment of a page rendering method of the present application.
  • the page rendering method includes:
  • Step S10 when receiving the browser page jump request, obtain the address of the page to be jumped according to the browser page jump request;
  • the page rendering method of this embodiment is implemented by a page rendering device.
  • the device is described as a front-end server.
  • the front-end server includes a router handler (RouterHandler) and also provides an API (Application Programming Interface, application program interface) to It is used for the configuration of routing information to generate routing configuration files.
  • this embodiment is implemented based on Vue.js.
  • Vue is a progressive framework for building user interfaces. Unlike other large frameworks, Vue is designed to be applied layer by layer from the bottom up. Vue's core library only focuses on the view layer, which is not only easy to use, but also easy to integrate with third-party libraries or existing projects.
  • Vue is also fully capable of providing complex single-page web applications (SPA, single page web application) to provide the driver.
  • SPA single page web application
  • the routing processor provides a push function (for jumping to a different browser address) for the user to call.
  • a push function for jumping to a different browser address
  • the push function is executed in the button logic to jump to
  • the browser address url uniform resource locator, uniform resource locator
  • the popstate event event in the HTML5 history series
  • the route processor will receive the browser page jump request, and then obtain the address of the page to be jumped according to the browser page jump request. Specifically, the address of the page to be jumped can be obtained from the object event (event) of the popstate event.
  • Step S20 obtaining a route matching the address of the page to be jumped from a pre-generated routing configuration file, and obtaining a matching routing path of the matching route;
  • the routing path of the matching route is Recorded as matching routing path.
  • the routing configuration file is generated in advance according to the Pages (page) directory set by the user, and the specific generation process may refer to the following second embodiment, which will not be repeated here.
  • a regular matching method may be used to perform matching, and the specific matching process may refer to the prior art.
  • Step S30 scoring each matched route according to the matching routing path, and determining a target route according to the scoring result
  • step S30 includes:
  • Step a31 splitting the matching routing path to obtain the number of sub-items of each matching route, and calculating the first score according to the number of sub-items and the first preset score;
  • the scoring process of routing is as follows:
  • the matching routing paths are split to obtain the number of sub-items of each matching route, and the first score is calculated according to the number of sub-items and the first preset score. Since the routing path is a string composed of multiple "/"s, when splitting the matching routing path, the matching routing path can be split according to the character "/" to obtain each subsection that constitutes the routing path. item.
  • the first score is the product of the number of sub-items and the first preset score, where the first preset score is a preset score of a single sub-item.
  • Step a32 obtain the sub-item type of each sub-item of each matched route, and determine the second score of each sub-item of each matched route according to the sub-item type;
  • the sub-item type of each sub-item of each matched route is acquired, and the second score of each sub-item of each matched route is determined according to the sub-item type.
  • the child types include static, dynamic, fuzzy matching and root end.
  • step a32 includes:
  • Step a321 detecting whether each sub-item of each matching route includes a preset special character, and obtaining a first detection result
  • Step a322 detecting whether each sub-item of each matching route is the root end, and obtaining a second detection result
  • Step a323 determining the sub-item type of each sub-item according to the first detection result and the second detection result;
  • Step a324 Determine the second score of each sub-item of each matching route according to the sub-item type and the mapping relationship between the preset sub-item type and the score.
  • the sub-item type of each sub-item is determined according to the first detection result and the second detection result, and if the sub-item does not include the first preset special character ":" and the second preset character "*", the sub-item type is determined is static; if the sub-item includes the first preset special character ":”, the sub-item type is determined to be dynamic; if the sub-item includes the second preset character "*", it is determined that the sub-item type is a fuzzy match; If the subkey is only "/", it is determined that the subkey type is the root end.
  • the second score of each sub-item of each matching route is determined.
  • the mapping relationship between the preset sub-item types and scores includes scores corresponding to different sub-item types.
  • the score corresponding to the sub-item type of static is recorded as the second preset score
  • the score corresponding to the sub-item type of dynamic is recorded as the third preset score
  • the sub-item type is corresponding to fuzzy matching.
  • the score is recorded as the fourth preset score
  • the score corresponding to the sub-item type as the root end is recorded as the fifth preset score.
  • the score corresponding to each sub-item can be set (that is, the first pre-match Set the score) as the maximum value; secondly, because the static priority is greater than the dynamic priority than the root end, the priority of fuzzy matching is the lowest. Therefore, the first preset score>the second preset score>the third preset score>the fifth preset score>the fourth preset score can be set.
  • Step a33 adding the first score and the second score to obtain the score of each matching route
  • Step a34 Determine the route corresponding to the maximum value in the score as the target route.
  • the first score and the second score are added to obtain the score of each matching route, and then the route corresponding to the maximum value in the score is determined as the target route.
  • Step S40 determining a target component corresponding to the target route according to the routing configuration file, and loading the target component to render a target page corresponding to the address of the page to be redirected.
  • the target component corresponding to the target route is determined according to the routing configuration file, and the target component is loaded to render the target page corresponding to the address of the page to be jumped.
  • the routing configuration file includes routing data of each route, wherein the routing data includes at least routing path information, component information, and may also include routing name, meta tag (an auxiliary tag in the head area of html language) and Parent-child relationship information, etc.
  • the meta tag can be used to mark whether the route needs some additional information such as login, status tag, etc.
  • the component of the target route can be directly used as the target component, and then the current routing component corresponding to the current browser is unloaded, and the target component is loaded to render the target page corresponding to the address of the page to be jumped.
  • the current routing path corresponding to the current page address can be obtained first, and the target routing path of the target routing can be obtained. Then, the current routing path can be split to obtain the first sub-item array, and the target routing path can be divided. Split the routing path to obtain the second sub-item array; compare the first sub-item array with the second sub-item array to obtain the public routing path and the non-public routing path, determine the target component according to the non-public routing path, and determine the target component according to the common routing path. The routing path determines the common routing component, and then unloads the components except the common routing component in the current routing component corresponding to the current routing path, and loads the target component to render the target page corresponding to the address of the page to be jumped.
  • An embodiment of the present application provides a method for page rendering.
  • a browser page jump request When a browser page jump request is received, the address of the page to be jumped is obtained according to the browser page jump request; The route matching the address of the page to be jumped is obtained, and the matching routing path of the matching routing is obtained; the matching routing is scored according to the matching routing path, and the target routing is determined according to the scoring result; The routing configuration file determines the target component corresponding to the target route, and loads the target component to render the target page corresponding to the address of the page to be redirected.
  • a matching route is obtained through a pre-generated routing configuration file, then the matching route is scored to determine the target route, and then the target component corresponding to the target route is loaded to realize page rendering. In this way, accurate and intelligent matching of routes can be achieved, and the best route can be determined for page rendering.
  • routing configuration that is, the mapping relationship between page paths and rendering components.
  • the routing configuration needs to be modified synchronously, which consumes development time, increases development labor costs, and reduces development efficiency.
  • the page rendering method further includes:
  • Step A when receiving a routing setting request, displaying a page directory setting interface according to the routing setting request;
  • the developer can trigger a routing setting request through the development terminal (such as a PC, a mobile phone, etc.).
  • the front-end server receives the routing setting request, it can display the page directory setting interface according to the routing setting request.
  • the page directory setting interface can display the following path specifications for user input:
  • Step B when receiving the input completion instruction triggered by the user based on the page directory setting interface, obtain the page directory input by the user;
  • the page directory input by the user that is, the pages directory is obtained.
  • Step C traverse the page directory, and detect whether there is a sub-routing file in the folder corresponding to the currently traversed page directory;
  • step D is performed to obtain the file name of the currently traversed sub-routing file, determine the routing type according to the file name, and generate second routing data according to the routing type and the file name;
  • the file name of the currently traversed sub-routing file is obtained, and the routing type is determined according to the file name. Specifically, when determining the routing type, if it is detected that the file name includes index.vue, the routing type is determined to be the default routing; if the special character @ is detected in the file name, the routing type is determined to be dynamic routing; if If it is detected that the file name includes *.vue, the route type is determined to be fuzzy matching; if it is detected that the file name only includes .vue, the route type is determined to be a regular route. Then, the second routing data is generated according to the routing type and the file name.
  • the second routing data includes at least routing path information and component information, and may also include routing names, meta tags, parent-child relationship information, and the like.
  • Step E acquiring the layout file corresponding to the sub-routing file and its first routing data, and updating the first routing data according to the second routing data;
  • step D and step E After detecting the existence of the sub-routing file, acquire the layout file corresponding to the sub-routing file and its first routing data, and update the first routing data according to the second routing data. It should be noted that the execution order of step D and step E is not in any particular order.
  • step E includes:
  • Step E1 detecting whether there is a layout file in the folder corresponding to the currently traversed page directory
  • step E21 is executed to determine that the layout file in the folder corresponding to the currently traversed page directory is the layout route corresponding to the sub-routing file;
  • step E22 is performed to detect whether there is a corresponding layout route in the upper-level directory of the currently traversed page directory;
  • step E23 determines that the layout route in the upper-level directory of the currently traversed page directory is the layout route corresponding to the sub-routing file;
  • Step E3 Acquire the first routing data of the layout route, and update the first routing data of the corresponding layout route according to the second routing data.
  • the readdirSync function provided by node.js can be used to traverse the page directory to detect the file corresponding to the currently traversed page directory Whether there is a layout file in the folder, specifically, by detecting whether the file suffix in the folder exists layout.vue, to detect whether there is a layout file.
  • the first routing data of the layout routing includes at least routing path information and component information, and may also include routing names, meta tags, parent-child relationship information, and the like.
  • the routing path information of the layout routing is obtained according to the path address of the file relative to the src/pages directory, and then removing the file suffix.
  • special characters in the file name need to be replaced to obtain a route that conforms to the preset code specification.
  • Path information so that the URL of the page to be jumped can be obtained by subsequent analysis according to the replaced routing path information. For example, replace "@" in dynamic routing with ":”, and replace "/index” in default routing with "/” , and replace "/layout” in the parent route with "/”.
  • the component information is the information of the component corresponding to the route, which is the absolute path of the file.
  • the route name name is based on the path address of the file relative to the pages directory. Name will be used as a variable in the code to resolve the URL of the page to be jumped. It also needs to conform to the preset code specification, so some special characters also need to be specified. Substitution, for example, replace "@" in dynamic routing with "_”, remove the file suffix, and then convert "/" into “_”.
  • the meta tag can be used to mark whether the route needs some additional information such as login, status tag, etc.
  • the parent-child relationship information is the relationship between the parent route and the child route.
  • the first routing data of the layout route is acquired, the first routing data of the corresponding layout route is updated according to the second routing data. Specifically, the second routing data is pushed into the children (child node) attribute of the layout routing (that is, the parent routing), so as to update the parent-child relationship information of the parent routing.
  • step E it also includes:
  • Step F Generate the routing configuration file according to the updated first routing data and the second routing data.
  • a routing configuration file is generated according to the updated first routing data and the second routing data.
  • step F includes:
  • Step F1 executing a preset template on the updated first routing data and the second routing data, and generating the dependency import logic of each route;
  • Step F2 writing the dependency import logic into a preset routing configuration template to obtain an initial routing configuration file
  • Step F3 Compile the initial routing configuration file to obtain the routing configuration file.
  • a container Root with an empty array structure may be created first and placed in a container Root with an empty array structure (root), and then construct the code of the routing configuration file (route.config.js) according to the JavaScript syntax specification.
  • a preset template is first executed on the updated first routing data and the second routing data, and the dependency import logic of each route is generated, wherein the preset template is "import ⁇ name ⁇ from ' in one embodiment.
  • ⁇ component ⁇ ';" which can recursively traverse the Root container, execute a template for each route item in the Root container, and generate the import logic for each route. That is, the component name and routing file address (that is, routing path information) in the routing data corresponding to the route are obtained by executing the preset template, then ⁇ name ⁇ in the preset template is replaced with the component name, and the preset template Replace the ⁇ component ⁇ in the route file address with the route's dependency import logic.
  • the dependency import logic code of the "pages/a.vue” component is "import a from 'project/src/pages/a.vue'", and then written to the route.config.js header. Then, the dependency introduction logic is written into a preset routing configuration template to obtain an initial routing configuration file.
  • the initial routing configuration file cannot be directly run by the browser, it is also necessary to compile the initial routing configuration file to obtain the routing configuration file. At compile time, it can be compiled via webpack (module bundler).
  • steps A-F may be executed on the developer end.
  • the intelligent generation of the routing configuration file can be realized, and the developer does not need to manually write the routing configuration every time, which can save development time and cost, and improve the configuration efficiency of the routing configuration file.
  • the page rendering method further includes:
  • Step G obtaining the single-file component pre-written by the user, and compiling the single-file component
  • the step of "loading the target component to render the target page corresponding to the address of the page to be jumped" includes:
  • the target component is loaded from the compiled single-file component to render the target page corresponding to the address of the page to be jumped.
  • the target component is loaded from the compiled single-file component to render the target page corresponding to the address of the page to be jumped.
  • step G may be performed simultaneously with the execution of the above-mentioned step F3.
  • the input page directory and single-file component can be obtained, and then the initial routing configuration file can be generated according to the page directory and compiled, and the single-file component can be compiled at the same time.
  • the above process may also be executed on the developer side, and then directly transmitted to the routing processor in the front-end server.
  • step S40 includes:
  • Step a41 obtain the current routing path corresponding to the current page address, and obtain the target routing path of the target route;
  • the current routing path corresponding to the current page address may be obtained first, and the target routing path of the target route may be obtained. That is, the current route corresponding to the current page address is obtained first, and then the routing path of the current route is obtained, which is recorded as the current routing path.
  • Step a42 splitting the current routing path to obtain a first sub-item array, and splitting the target routing path to obtain a second sub-item array;
  • the current routing path is split to obtain the first sub-item array
  • the target routing path is split to obtain the second sub-item array.
  • the matching routing path can be split according to the character "/"
  • Step a43 compare the first sub-item array with the second sub-item array, obtain a public routing path and a non-public routing path, and determine a target component according to the non-public routing path;
  • the first sub-item array is compared with the second sub-item array, so that the public routing path and the non-public routing path can be obtained.
  • the specific comparison method is: according to the order of the array labels from small to large, judge whether the first sub-item array and the second sub-item array of the same label are equal, that is, if the first sub-item array is a[], the second sub-item array is equal to
  • the item array is b[], starting from label 0, first judge whether a[0] is equal to b[0], if so, continue to judge whether a[1] is equal to b[1], and so on, until a[n] ] and b[n] are not equal, the equal part is the path common to the current routing path and the target routing path, which is recorded as the common routing path, and the non-public routing path is the part of the target routing path that is different from the current routing path, that is The part of the destination routing path excluding the public routing path.
  • target components are determined based on non-public routing paths. That is, target components are determined based on non-public routing paths and routing profiles.
  • Step a44 Determine a common routing component according to the common routing path, unload components other than the common routing component in the current routing components corresponding to the current routing path, and load the target component.
  • the common routing component is determined according to the common routing path, the components except the common routing component in the current routing components corresponding to the current routing path are unloaded, and the target component is loaded.
  • the same part of the content can be designed as the parent route /user, then the page /user/a and page /user/b contain different content respectively (for example, corresponding to components A and B respectively), then route /user/a and route /user/b are used as child routes of the parent route, When switching from /user/a to /user/b, it can be determined that the target component is B. In this case, load B after unloading A.
  • the present application also provides a page rendering apparatus.
  • FIG. 3 is a schematic diagram of functional modules of the first embodiment of the page rendering apparatus of the present application.
  • the page rendering apparatus includes:
  • the first obtaining module 10 is configured to, when receiving a browser page jump request, obtain the address of the page to be jumped according to the browser page jump request;
  • a second obtaining module 20 configured to obtain a route matching the address of the page to be jumped from a pre-generated routing configuration file, and obtain a matching routing path of the matching route;
  • the route scoring module 30 is used for scoring each matched route according to the matching routing path, and determining the target route according to the scoring result;
  • the page rendering module 40 is configured to determine the target component corresponding to the target route according to the routing configuration file, and load the target component to render the target page corresponding to the address of the page to be jumped.
  • the route scoring module 30 includes:
  • a first calculation unit configured to split the matching routing path, obtain the number of sub-items of each matching route, and calculate and obtain a first score according to the number of sub-items and a first preset score
  • a first determining unit configured to obtain the sub-item type of each sub-item of each matched route, and determine the second score of each sub-item of each matched route according to the sub-item type
  • a second computing unit configured to add the first score and the second score to obtain the scores of each matching route
  • the second determining unit is configured to determine the route corresponding to the maximum value in the score as the target route.
  • the first determining unit is specifically used for:
  • the second score of each sub-item of each matching route is determined according to the sub-item type and the mapping relationship between the preset sub-item type and the score.
  • the page rendering apparatus further includes:
  • an interface display module configured to display a page directory setting interface according to the route setting request when receiving the route setting request
  • a third acquiring module configured to acquire the page directory input by the user when receiving an input completion instruction triggered by the user based on the page directory setting interface
  • the first detection module is used to traverse the page directory and detect whether there is a sub-routing file in the folder corresponding to the currently traversed page directory;
  • the fourth obtaining module is used to obtain the file name of the currently traversed sub-routing file if there is a sub-routing file, determine the routing type according to the file name, and generate the second routing data according to the routing type and the file name ;
  • a data update module configured to obtain the layout file corresponding to the sub-routing file and its first routing data, and update the first routing data according to the second routing data;
  • a file generation module configured to generate the routing configuration file according to the updated first routing data and the second routing data.
  • the data update module includes:
  • the first detection unit is used to detect whether there is a layout file in the folder corresponding to the currently traversed page directory
  • a third determining unit configured to determine that the layout file in the folder corresponding to the currently traversed page directory is the layout route corresponding to the sub-routing file if there is a layout file in the folder corresponding to the currently traversed page directory;
  • the second detection unit is configured to detect whether there is a corresponding layout route in the upper-level directory of the currently traversed page directory if there is no layout file in the folder corresponding to the currently traversed page directory;
  • the fourth determining unit is configured to determine that the layout route in the upper-level directory of the currently traversed page directory is the layout route corresponding to the sub-routing file if there is a corresponding layout route in the upper-level directory of the currently traversed page directory;
  • a data updating unit configured to acquire the first routing data of the layout route, and update the first routing data of the corresponding layout route according to the second routing data.
  • the file generation module includes:
  • a template execution unit configured to execute a preset template on the updated first routing data and the second routing data, and generate dependency import logic for each route;
  • a logic writing unit configured to write the dependency import logic into a preset routing configuration template to obtain an initial routing configuration file
  • a file compiling unit configured to compile the initial routing configuration file to obtain the routing configuration file.
  • the page rendering module 40 includes:
  • the first obtaining unit is used to obtain the current routing path corresponding to the current page address, and obtain the target routing path of the target routing;
  • a path splitting unit for splitting the current routing path to obtain a first sub-item array, and splitting the target routing path to obtain a second sub-item array
  • an array comparison unit configured to compare the first sub-item array with the second sub-item array to obtain a public routing path and a non-public routing path, and determine a target component according to the non-public routing path;
  • a component loading unit configured to determine a common routing component according to the common routing path, unload components other than the common routing component in the current routing components corresponding to the current routing path, and load the target component.
  • each module in the above-mentioned page rendering apparatus corresponds to each step in the above-mentioned page rendering method embodiment, and the functions and implementation process thereof will not be repeated here.
  • the present application further provides a computer-readable storage medium, where a page rendering program is stored on the computer-readable storage medium, and when the page rendering program is executed by a processor, the page rendering method according to any one of the above embodiments is implemented. step.

Abstract

A page rendering method, apparatus, and device, and a computer readable storage medium, relating to the technical field of financial technology. The page rendering method comprises: upon receiving a browser page skipping request, obtaining, according to the browser page skipping request, the address of a page to be skipped (S10); obtaining, from a pre-generated route configuration file, routes matched with the address of said page, and obtaining the matched routing paths of the matched routes (S20); scoring each matched route according to the matched routing paths, and determining a target route according to scoring results (S30); and determining a target component corresponding to the target route according to the route configuration file, and loading the target component to render to obtain a target page corresponding to the address of said page (S40).

Description

页面渲染方法、装置、设备及计算机可读存储介质Page rendering method, apparatus, device, and computer-readable storage medium
本申请要求于2020年8月12日申请的、申请号为202010809562.6的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with application number 202010809562.6 filed on August 12, 2020, the entire contents of which are incorporated herein by reference.
技术领域technical field
本申请涉及金融科技(Fintech)技术领域,尤其涉及一种页面渲染方法、装置、设备及计算机可读存储介质。The present application relates to the technical field of financial technology (Fintech), and in particular, to a page rendering method, apparatus, device, and computer-readable storage medium.
背景技术Background technique
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,但由于金融行业的安全性、实时性要求,也对技术提出了更高的要求。With the development of computer technology, more and more technologies are applied in the financial field, and the traditional financial industry is gradually transforming into financial technology (Fintech). requirements.
现有的页面渲染方式包括服务端渲染和客户端渲染,分别适用于不同的开发与业务场景。其中,服务端渲染又称为后端渲染,可基于Spring MVC(一种java框架)实现,在页面渲染过程中,浏览器请求服务端,服务端先匹配到对应路由,执行路由对应的处理器,以在处理器中处理业务逻辑,再根据数据和渲染模板生成HTML(HyperText Mark-up Language,超文本标记语言)文件内容返回给浏览器,整个流程耗时较长,导致打开页面很慢,用户体验不够好。对此,目标通常会采用客户端渲染的方式进行页面渲染。Existing page rendering methods include server-side rendering and client-side rendering, which are suitable for different development and business scenarios. Among them, server-side rendering, also known as back-end rendering, can be implemented based on Spring MVC (a java framework). During the page rendering process, the browser requests the server, and the server first matches the corresponding route and executes the processor corresponding to the route. , to process business logic in the processor, and then generate HTML (HyperText Mark-up Language, hypertext markup language) file content is returned to the browser, and the whole process takes a long time, resulting in slow page opening and poor user experience. In this regard, the target usually uses client-side rendering to render the page.
客户端渲染又称为前端渲染,可基于React Router(一种路由解决方案)应用程序来实现。在页面渲染过程中,会通过比较Route(路由)组件的path(路径)属性和浏览器页面地址进行路由匹配,如果页面路径匹配到路由有多个,React Router会选择渲染第一个。然而,这种匹配方式并不合理。例如,用户同时定义了路由/order/:orderId(订单详情页)和/order/list(订单列表页),当用户访问/order/list时能匹配到订单详情页和订单列表页面。此时,React Router会渲染匹配到的第一个订单详情页,但实际上渲染订单列表页面更加合理。因此,现有的路由匹配方案并不准确。Client-side rendering, also known as front-end rendering, can be implemented based on React Router (a routing solution) application. During page rendering, route matching is performed by comparing the path attribute of the Route component with the browser page address. If the page path matches multiple routes, React Router will choose to render the first one. However, this matching method is not reasonable. For example, the user defines the routes /order/:orderId (order details page) and /order/list (order list page) at the same time, when the user accesses /order/list, the order details page and the order list page can be matched. At this point, React Router will render the first order details page that matches, but it's actually more reasonable to render the order list page. Therefore, existing route matching schemes are not accurate.
技术问题technical problem
本申请的主要目的在于提供一种页面渲染方法、装置、设备及计算机可读存储介质,旨在解决前端渲染过程中路由匹配方案不准确的问题。The main purpose of the present application is to provide a page rendering method, apparatus, device and computer-readable storage medium, aiming at solving the problem of inaccurate routing matching scheme in the front-end rendering process.
技术解决方案technical solutions
为实现上述目的,本申请提供一种页面渲染方法,所述页面渲染方法包括:In order to achieve the above purpose, the present application provides a page rendering method, the page rendering method includes:
在接收到浏览器页面跳转请求时,根据所述浏览器页面跳转请求获取待跳转页面地址;When receiving the browser page jump request, obtain the address of the page to be jumped according to the browser page jump request;
从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径;Obtain a route matching the address of the page to be redirected from a pre-generated routing configuration file, and obtain a matching routing path of the matching route;
根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由;Score each matching route according to the matching routing path, and determine the target route according to the scoring result;
根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面。The target component corresponding to the target route is determined according to the routing configuration file, and the target component is loaded to render the target page corresponding to the address of the page to be redirected.
此外,为实现上述目的,本申请还提供一种页面渲染装置,所述页面渲染装置包括:In addition, in order to achieve the above purpose, the present application also provides a page rendering device, the page rendering device comprising:
第一获取模块,用于在接收到浏览器页面跳转请求时,根据所述浏览器页面跳转请求获取待跳转页面地址;a first obtaining module, configured to obtain the address of the page to be jumped according to the browser page jump request when receiving the browser page jump request;
第二获取模块,用于从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径;A second obtaining module, configured to obtain a route matching the address of the page to be jumped from a pre-generated routing configuration file, and obtain a matching routing path of the matching route;
路由评分模块,用于根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由;A route scoring module, for scoring each matched route according to the matching routing path, and determining a target route according to the scoring result;
页面渲染模块,用于根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面。A page rendering module, configured to determine a target component corresponding to the target route according to the routing configuration file, and load the target component to render a target page corresponding to the address of the page to be jumped.
此外,为实现上述目的,本申请还提供一种页面渲染设备,所述页面渲染设备包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的页面渲染程序,所述页面渲染程序被所述处理器执行时实现如上所述的页面渲染方法的步骤。In addition, in order to achieve the above object, the present application also provides a page rendering device, the page rendering device includes: a memory, a processor, and a page rendering program stored in the memory and running on the processor, When the page rendering program is executed by the processor, the steps of the above-mentioned page rendering method are implemented.
此外,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有页面渲染程序,所述页面渲染程序被处理器执行时实现如上所述的页面渲染方法的步骤。In addition, in order to achieve the above purpose, the present application also provides a computer-readable storage medium, where a page rendering program is stored on the computer-readable storage medium, and when the page rendering program is executed by a processor, the above-mentioned page rendering is realized steps of the method.
有益效果beneficial effect
本申请提供一种页面渲染方法、装置、设备及计算机可读存储介质,在接收到浏览器页面跳转请求时,根据所述浏览器页面跳转请求获取待跳转页面地址;然后,从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径;根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由;进而根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面。本申请中,通过预先生成的路由配置文件获得相匹配的路由,然后对相匹配的路由进行评分,确定出目标路由,进而加载目标路由对应的目标组件,以实现页面的渲染,通过上述方式,可实现路由的精准智能匹配,确定出最佳路由来进行页面渲染。The present application provides a page rendering method, apparatus, device and computer-readable storage medium. When a browser page jump request is received, the address of the page to be jumped is obtained according to the browser page jump request; Obtain the route that matches the address of the page to be jumped from the generated routing configuration file, and obtain the matching routing path of the matching route; score each matching route according to the matching routing path, and The scoring result determines a target route; further, a target component corresponding to the target route is determined according to the routing configuration file, and the target component is loaded to render the target page corresponding to the address of the page to be redirected. In this application, a matching route is obtained through a pre-generated routing configuration file, and then the matching route is scored to determine the target route, and then the target component corresponding to the target route is loaded to realize page rendering. Through the above method, It can achieve precise and intelligent matching of routes, and determine the best route for page rendering.
附图说明Description of drawings
图1为本申请实施例方案涉及的硬件运行环境的设备结构示意图;FIG. 1 is a schematic diagram of the device structure of the hardware operating environment involved in the solution of the embodiment of the present application;
图2为本申请页面渲染方法第一实施例的流程示意图;2 is a schematic flowchart of a first embodiment of a page rendering method of the present application;
图3为本申请页面渲染装置第一实施例的功能模块示意图。FIG. 3 is a schematic diagram of functional modules of the first embodiment of the page rendering apparatus of the present application.
本发明的实施方式Embodiments of the present invention
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。It should be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application.
参照图1,图1为本申请实施例方案涉及的硬件运行环境的设备结构示意图。Referring to FIG. 1 , FIG. 1 is a schematic diagram of a device structure of a hardware operating environment involved in the solution of an embodiment of the present application.
本申请实施例页面渲染设备可以是智能手机,也可以是PC(Personal Computer,个人计算机)、平板电脑、便携计算机等终端设备。The page rendering device in this embodiment of the present application may be a smartphone, or a PC (Personal Computer, personal computer), tablet computer, portable computer and other terminal equipment.
如图1所示,该页面渲染设备可以包括:处理器1001,例如CPU,通信总线1002,用户接口1003,网络接口1004,存储器1005。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如Wi-Fi接口)。存储器1005可以是高速RAM存储器,也可以是稳定的存储器(non-volatile memory),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。As shown in FIG. 1 , the page rendering device may include: a processor 1001 , such as a CPU, a communication bus 1002 , a user interface 1003 , a network interface 1004 , and a memory 1005 . Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. Optionally, the network interface 1004 may include a standard wired interface and a wireless interface (eg, a Wi-Fi interface). The memory 1005 may be high-speed RAM memory, or may be non-volatile memory, such as disk memory. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001 .
本领域技术人员可以理解,图1中示出的页面渲染设备结构并不构成对页面渲染设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Those skilled in the art can understand that the structure of the page rendering device shown in FIG. 1 does not constitute a limitation to the page rendering device, and may include more or less components than the one shown, or combine some components, or different components layout.
如图1所示,作为一种计算机存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及页面渲染程序。As shown in FIG. 1 , the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module and a page rendering program.
在图1所示的终端中,网络接口1004主要用于连接后台服务器,与后台服务器进行数据通信;用户接口1003主要用于连接客户端,与客户端进行数据通信;而处理器1001可以用于调用存储器1005中存储的页面渲染程序,并执行以下页面渲染方法的各个步骤。In the terminal shown in FIG. 1 , the network interface 1004 is mainly used to connect to the background server and perform data communication with the background server; the user interface 1003 is mainly used to connect to the client and perform data communication with the client; and the processor 1001 can be used for The page rendering program stored in the memory 1005 is called, and each step of the following page rendering method is executed.
基于上述硬件结构,提出本申请页面渲染方法的各实施例。Based on the above hardware structure, various embodiments of the page rendering method of the present application are proposed.
本申请提供一种页面渲染方法。The present application provides a page rendering method.
参照图2,图2为本申请页面渲染方法第一实施例的流程示意图。Referring to FIG. 2 , FIG. 2 is a schematic flowchart of a first embodiment of a page rendering method of the present application.
在本实施例中,该页面渲染方法包括:In this embodiment, the page rendering method includes:
步骤S10,在接收到浏览器页面跳转请求时,根据所述浏览器页面跳转请求获取待跳转页面地址;Step S10, when receiving the browser page jump request, obtain the address of the page to be jumped according to the browser page jump request;
本实施例的页面渲染方法是由页面渲染设备实现的,该设备以前端服务器进行说明,该前端服务器中包括路由处理器(RouterHandler),还提供一API(Application Programming Interface,应用程序接口),以用于路由信息的配置,进而生成路由配置文件。此外,本实施例是基于Vue.js实现的。Vue是一套用于构建用户界面的渐进式框架。与其它大型框架不同的是,Vue被设计为可以自底向上逐层应用。Vue的核心库只关注视图层,不仅易于上手,还便于与第三方库或既有项目整合。另一方面,当与现代化的工具链以及各种支持类库结合使用时,Vue也完全能够为复杂的单页Web应用(SPA,single page web application)提供驱动。The page rendering method of this embodiment is implemented by a page rendering device. The device is described as a front-end server. The front-end server includes a router handler (RouterHandler) and also provides an API (Application Programming Interface, application program interface) to It is used for the configuration of routing information to generate routing configuration files. In addition, this embodiment is implemented based on Vue.js. Vue is a progressive framework for building user interfaces. Unlike other large frameworks, Vue is designed to be applied layer by layer from the bottom up. Vue's core library only focuses on the view layer, which is not only easy to use, but also easy to integrate with third-party libraries or existing projects. On the other hand, when combined with modern toolchains and various supporting libraries, Vue is also fully capable of providing complex single-page web applications (SPA, single page web application) to provide the driver.
在本实施例中,路由处理器提供push函数(用于跳转到不同的浏览器地址)给用户调用,当用户点击浏览器中的某个按钮时,在按钮逻辑里面执行push函数以跳转至新的路由,此时浏览器地址url(uniform resource locator,统一资源定位系统)会发生变化,在页面的window(窗口)对象上触发popstate事件(HTML5的历史系列中的事件),此时,路由处理器会接收到浏览器页面跳转请求,进而根据浏览器页面跳转请求获取待跳转页面地址,具体的,可从popstate事件的对象event(事件)中拿到待跳转页面地址。In this embodiment, the routing processor provides a push function (for jumping to a different browser address) for the user to call. When the user clicks a button in the browser, the push function is executed in the button logic to jump to To the new route, the browser address url (uniform resource locator, uniform resource locator) will change, and the popstate event (event in the HTML5 history series) will be triggered on the window (window) object of the page. At this time, The route processor will receive the browser page jump request, and then obtain the address of the page to be jumped according to the browser page jump request. Specifically, the address of the page to be jumped can be obtained from the object event (event) of the popstate event.
步骤S20,从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径;Step S20, obtaining a route matching the address of the page to be jumped from a pre-generated routing configuration file, and obtaining a matching routing path of the matching route;
然后,从预先生成的路由配置文件中获取与待跳转页面地址相匹配的路由,并获取相匹配的路由的路由路径,为与后续的其他路由路径相区分,将相匹配的路由的路由路径记为匹配路由路径。Then, obtain the route matching the address of the page to be redirected from the pre-generated routing configuration file, and obtain the routing path of the matching route. In order to distinguish it from other subsequent routing paths, the routing path of the matching route is Recorded as matching routing path.
其中,路由配置文件是预先根据用户设定的Pages(页面)目录生成得到的,具体的生成过程可参照下述第二实施例,此处不作赘述。在进行匹配时,可采用正则匹配的方式进行匹配,具体的匹配过程可参照现有技术。The routing configuration file is generated in advance according to the Pages (page) directory set by the user, and the specific generation process may refer to the following second embodiment, which will not be repeated here. When performing matching, a regular matching method may be used to perform matching, and the specific matching process may refer to the prior art.
步骤S30,根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由;Step S30, scoring each matched route according to the matching routing path, and determining a target route according to the scoring result;
由于匹配得到的路由通常包括多个,因此,在得到相匹配的路由的匹配路由路径之后,需根据匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由。Since there are usually multiple routes obtained by matching, after obtaining the matching routing paths of the matching routes, it is necessary to score the matching routes according to the matching routing paths, and determine the target route according to the scoring results.
具体的,步骤S30包括:Specifically, step S30 includes:
步骤a31,对所述匹配路由路径进行拆分,得到各相匹配的路由的子项数量,根据所述子项数量和第一预设分值计算得到第一得分;Step a31, splitting the matching routing path to obtain the number of sub-items of each matching route, and calculating the first score according to the number of sub-items and the first preset score;
在本实施例中,路由的评分过程具体如下:In this embodiment, the scoring process of routing is as follows:
先对匹配路由路径进行拆分,得到各相匹配的路由的子项数量,根据子项数量和第一预设分值计算得到第一得分。由于路由路径是多个“/”组成的字符串,因此,在对匹配路由路径进行拆分时,可根据“/”这一字符对匹配路由路径进行拆分,以得到构成路由路径的各个子项。第一得分为子项数量与第一预设分值的乘积,其中,第一预设分值即为预先设置的单个子项的分值。First, the matching routing paths are split to obtain the number of sub-items of each matching route, and the first score is calculated according to the number of sub-items and the first preset score. Since the routing path is a string composed of multiple "/"s, when splitting the matching routing path, the matching routing path can be split according to the character "/" to obtain each subsection that constitutes the routing path. item. The first score is the product of the number of sub-items and the first preset score, where the first preset score is a preset score of a single sub-item.
步骤a32,获取各相匹配的路由的各子项的子项类型,并根据所述子项类型确定各相匹配的路由的各子项的第二得分;Step a32, obtain the sub-item type of each sub-item of each matched route, and determine the second score of each sub-item of each matched route according to the sub-item type;
然后,获取各相匹配的路由的各子项的子项类型,并根据子项类型确定各相匹配的路由的各子项的第二得分。其中,子项类型包括静态、动态、模糊匹配和根端。Then, the sub-item type of each sub-item of each matched route is acquired, and the second score of each sub-item of each matched route is determined according to the sub-item type. Among them, the child types include static, dynamic, fuzzy matching and root end.
具体的,步骤a32包括:Specifically, step a32 includes:
步骤a321,检测各相匹配的路由的各子项中是否包括预设特殊字符,得到第一检测结果;Step a321, detecting whether each sub-item of each matching route includes a preset special character, and obtaining a first detection result;
步骤a322,检测各相匹配的路由的各子项是否为根端,得到第二检测结果;Step a322, detecting whether each sub-item of each matching route is the root end, and obtaining a second detection result;
步骤a323,根据所述第一检测结果和所述第二检测结果确定各子项的子项类型;Step a323, determining the sub-item type of each sub-item according to the first detection result and the second detection result;
步骤a324,根据所述子项类型和预设子项类型与分值之间的映射关系,确定各相匹配的路由的各子项的第二得分。Step a324: Determine the second score of each sub-item of each matching route according to the sub-item type and the mapping relationship between the preset sub-item type and the score.
第二得分的具体获取过程:The specific acquisition process of the second score:
先检测各相匹配的路由的各子项中是否包括预设特殊字符,得到第一检测结果,其中,预设特征字符包括第一预设特殊字符“:”和第二预设字符“*”。同时,检测各相匹配的路由的各子项是否为根端,得到第二检测结果。在检测根端时,是判断子项是否只是“/”。First detect whether each sub-item of each matching route includes preset special characters, and obtain a first detection result, wherein the preset characteristic characters include the first preset special character ":" and the second preset character "*" . At the same time, it is detected whether each sub-item of each matched route is the root end, and a second detection result is obtained. When detecting the root end, it is to determine whether the child is just "/".
然后,根据第一检测结果和第二检测结果确定各子项的子项类型,若子项中不包括第一预设特殊字符“:”和第二预设字符“*”,则确定子项类型是静态的;若子项中包括第一预设特殊字符“:”,则确定子项类型是动态的;若子项中包括第二预设字符“*”,则确定子项类型是模糊匹配的;若子项只是“/”,则确定子项类型为根端。Then, the sub-item type of each sub-item is determined according to the first detection result and the second detection result, and if the sub-item does not include the first preset special character ":" and the second preset character "*", the sub-item type is determined is static; if the sub-item includes the first preset special character ":", the sub-item type is determined to be dynamic; if the sub-item includes the second preset character "*", it is determined that the sub-item type is a fuzzy match; If the subkey is only "/", it is determined that the subkey type is the root end.
进而,根据子项类型和预设子项类型与分值之间的映射关系,确定各相匹配的路由的各子项的第二得分。其中,预设子项类型与分值之间的映射关系包括不同的子项类型所对应的分值。将子项类型为静态所对应的分值记为第二预设分值,将子项类型为动态所对应的分值记为第三预设分值,将子项类型为模糊匹配所对应的分值记为第四预设分值,将子项类型为根端所对应的分值记为第五预设分值。在设定各分值的大小时,是基于精准匹配优先算法原则进行设计限定的,由于匹配的子项越多,越接近完全匹配,因此可设置各子项对应的分值(即第一预设分值)为最大值;其次,由于静态的优先级大于动态大于根端,模糊匹配的优先级最低。因此,可设置第一预设分值>第二预设分值>第三预设分值>第五预设分值>第四预设分值。Further, according to the sub-item type and the mapping relationship between the preset sub-item type and the score, the second score of each sub-item of each matching route is determined. The mapping relationship between the preset sub-item types and scores includes scores corresponding to different sub-item types. The score corresponding to the sub-item type of static is recorded as the second preset score, the score corresponding to the sub-item type of dynamic is recorded as the third preset score, and the sub-item type is corresponding to fuzzy matching. The score is recorded as the fourth preset score, and the score corresponding to the sub-item type as the root end is recorded as the fifth preset score. When setting the size of each score, it is based on the principle of precise matching priority algorithm. Since the more sub-items are matched, the closer to complete matching, the score corresponding to each sub-item can be set (that is, the first pre-match Set the score) as the maximum value; secondly, because the static priority is greater than the dynamic priority than the root end, the priority of fuzzy matching is the lowest. Therefore, the first preset score>the second preset score>the third preset score>the fifth preset score>the fourth preset score can be set.
步骤a33,对所述第一得分和所述第二得分进行加和,得到各相匹配的路由的评分;Step a33, adding the first score and the second score to obtain the score of each matching route;
步骤a34,将所述评分中最大值所对应的路由确定为目标路由。Step a34: Determine the route corresponding to the maximum value in the score as the target route.
最后,对第一得分和第二得分进行加和,得到各相匹配的路由的评分,进而将评分中最大值所对应的路由确定为目标路由。Finally, the first score and the second score are added to obtain the score of each matching route, and then the route corresponding to the maximum value in the score is determined as the target route.
例如,当第一预设分值设为4、第二预设分值设为3、第三预设分值设为2、第四预设分值设为-1、第五预设分值设为1时,若匹配路由路径为/groups/:groupId,其子项数量为2,第一个子项groups是静态的,第二个子项:groupId是动态的,则确定其评分为2*4+3+2=13;若匹配路由路径为/,其子项数量为1,其子项是根端,则确定其评分为1*4+1=5;若匹配路由路径为/groups/:groupId/users/:userId,其子项数量为4,第一个子项groups是静态的,第二个子项:groupId是动态的,第三个子项users是静态的,第四个子项:userId是动态的,则确定其评分为4*4+3+2+3+2=26。For example, when the first preset score is set to 4, the second preset score is set to 3, the third preset score is set to 2, the fourth preset score is set to -1, and the fifth preset score is When set to 1, if the matching routing path is /groups/:groupId, the number of sub-items is 2, the first sub-item groups is static, and the second sub-item: groupId is dynamic, then the score is determined to be 2* 4+3+2=13; if the matching routing path is /, the number of sub-items is 1, and its sub-item is the root end, the score is determined to be 1*4+1=5; if the matching routing path is /groups/ :groupId/users/:userId, the number of sub-items is 4, the first sub-item groups is static, the second sub-item: groupId is dynamic, the third sub-item users is static, the fourth sub-item: userId is dynamic, then determine its score as 4*4+3+2+3+2=26.
步骤S40,根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面。Step S40, determining a target component corresponding to the target route according to the routing configuration file, and loading the target component to render a target page corresponding to the address of the page to be redirected.
最后,根据路由配置文件确定目标路由对应的目标组件,加载目标组件,以渲染得到待跳转页面地址对应的目标页面。具体的,路由配置文件中包括各路由的路由数据,其中,路由数据至少包括路由路径信息、组件信息,还可以包括路由名称、meta元标签(html语言head头部区的一个辅助性标签)和父子关系信息等,其中,meta标签可用于标注路由是否需要登录、状态标签等一些额外信息。Finally, the target component corresponding to the target route is determined according to the routing configuration file, and the target component is loaded to render the target page corresponding to the address of the page to be jumped. Specifically, the routing configuration file includes routing data of each route, wherein the routing data includes at least routing path information, component information, and may also include routing name, meta tag (an auxiliary tag in the head area of html language) and Parent-child relationship information, etc. Among them, the meta tag can be used to mark whether the route needs some additional information such as login, status tag, etc.
作为目标组件的一确定方式,可以直接将目标路由的组件作为目标组件,进而卸载当前浏览器对应的当前路由组件,并加载目标组件,以渲染得到待跳转页面地址对应的目标页面。As a way of determining the target component, the component of the target route can be directly used as the target component, and then the current routing component corresponding to the current browser is unloaded, and the target component is loaded to render the target page corresponding to the address of the page to be jumped.
作为目标组件的又一确定方式,可以先获取当前页面地址对应的当前路由路径,并获取目标路由的目标路由路径,然后,对当前路由路径进行拆分,得到第一子项数组,并对目标路由路径进行拆分,得到第二子项数组;将第一子项数组与第二子项数组进行比对,得到公共路由路径和非公共路由路径,根据非公共路由路径确定目标组件,根据公共路由路径确定公共路由组件,进而卸载当前路由路径对应的当前路由组件中除公共路由组件外的组件,并加载目标组件,以渲染得到待跳转页面地址对应的目标页面。As another way of determining the target component, the current routing path corresponding to the current page address can be obtained first, and the target routing path of the target routing can be obtained. Then, the current routing path can be split to obtain the first sub-item array, and the target routing path can be divided. Split the routing path to obtain the second sub-item array; compare the first sub-item array with the second sub-item array to obtain the public routing path and the non-public routing path, determine the target component according to the non-public routing path, and determine the target component according to the common routing path. The routing path determines the common routing component, and then unloads the components except the common routing component in the current routing component corresponding to the current routing path, and loads the target component to render the target page corresponding to the address of the page to be jumped.
本申请实施例提供一种页面渲染方法,在接收到浏览器页面跳转请求时,根据所述浏览器页面跳转请求获取待跳转页面地址;然后,从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径;根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由;进而根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面。本申请实施例中,通过预先生成的路由配置文件获得相匹配的路由,然后对相匹配的路由进行评分,确定出目标路由,进而加载目标路由对应的目标组件,以实现页面的渲染,通过上述方式,可实现路由的精准智能匹配,确定出最佳路由来进行页面渲染。An embodiment of the present application provides a method for page rendering. When a browser page jump request is received, the address of the page to be jumped is obtained according to the browser page jump request; The route matching the address of the page to be jumped is obtained, and the matching routing path of the matching routing is obtained; the matching routing is scored according to the matching routing path, and the target routing is determined according to the scoring result; The routing configuration file determines the target component corresponding to the target route, and loads the target component to render the target page corresponding to the address of the page to be redirected. In this embodiment of the present application, a matching route is obtained through a pre-generated routing configuration file, then the matching route is scored to determine the target route, and then the target component corresponding to the target route is loaded to realize page rendering. In this way, accurate and intelligent matching of routes can be achieved, and the best route can be determined for page rendering.
进一步地,目前,在使用React Router 应用程序实现页面渲染时,需要用户手动编写路由配置(即页面路径跟渲染组件的映射关系)。当路由组件的位置发生变化时,需要同步修改路由配置,较为耗费开发时间,增加了开发人力成本,且开发效率较低。Further, at present, when using React Router application to achieve page rendering, users need to manually write routing configuration (that is, the mapping relationship between page paths and rendering components). When the location of the routing component changes, the routing configuration needs to be modified synchronously, which consumes development time, increases development labor costs, and reduces development efficiency.
对此,基于上述第一实施例,提出本申请页面渲染方法的第二实施例。In this regard, based on the above-mentioned first embodiment, a second embodiment of the page rendering method of the present application is proposed.
在本实施例中,在上述步骤S20之前,该页面渲染方法还包括:In this embodiment, before the above step S20, the page rendering method further includes:
步骤A,在接收到路由设置请求时,根据所述路由设置请求显示页面目录设置界面;Step A, when receiving a routing setting request, displaying a page directory setting interface according to the routing setting request;
在本实施例中,开发人员可通过开发端(如pc、手机等)触发路由设置请求,此时,前端服务器在接收到路由设置请求时,可根据该路由设置请求显示页面目录设置界面。其中,页面目录设置界面可显示如下路径规范,以供用户输入:In this embodiment, the developer can trigger a routing setting request through the development terminal (such as a PC, a mobile phone, etc.). At this time, when the front-end server receives the routing setting request, it can display the page directory setting interface according to the routing setting request. Among them, the page directory setting interface can display the following path specifications for user input:
1  pages1 pages
2   ├ index.vue        # 根路由页面路径  index.html#/2 ├ index.vue # Root route page path index.html#/
3   ├ a.vue            # 路径 /a3 ├ a.vue # path/a
4   ├ b               4 ├ b
5   │├ index.vue     # 路径 /b5 │├ index.vue # path /b
6   │├ @id.vue      # 动态路由 /b/:id6 │├ @id.vue  # dynamic routing /b/:id
7   │└ c.vue         # 路径 /b/c7 │└ c.vue  # path /b/c
8   └  layout.vue       # 根路由下所有page共用的外层8 └ layout.vue # The outer layer shared by all pages under the root route
9   └  *.vue           # 路径 /*9 └ *.vue # path /*
其中,动态路由支持在路径中定义参数,例如,/order/1匹配/order/:id路由,路径中的/1解析为参数id=1。Among them, dynamic routing supports defining parameters in the path. For example, /order/1 matches the /order/:id route, and /1 in the path resolves to parameter id=1.
步骤B,在接收到用户基于所述页面目录设置界面触发的输入完成指令时,获取用户输入的页面目录;Step B, when receiving the input completion instruction triggered by the user based on the page directory setting interface, obtain the page directory input by the user;
当用户输入完成后,可接收到用户基于该页面目录设置界面触发的输入完成指令时,获取用户输入的页面目录,即pages目录。After the user's input is completed, when an input completion instruction triggered by the user based on the page directory setting interface can be received, the page directory input by the user, that is, the pages directory is obtained.
步骤C,遍历所述页面目录,检测当前遍历的页面目录所对应的文件夹中是否存在子路由文件;Step C, traverse the page directory, and detect whether there is a sub-routing file in the folder corresponding to the currently traversed page directory;
然后,通过node.js提供的readdirSync函数遍历页面目录,检测当前遍历的页面目录所对应的文件夹中是否存在子路由文件。具体的,可通过检测文件夹中的文件后缀是否存在除layout.vue外的.vue,来检测是否存在子路由文件。Then, traverse the page directory through the readdirSync function provided by node.js to detect whether there is a sub-routing file in the folder corresponding to the currently traversed page directory. Specifically, it is possible to detect whether there is a sub-routing file by detecting whether the file suffix in the folder has .vue other than layout.vue.
若存在子路由文件,则执行步骤D,获取当前遍历的子路由文件的文件名,根据所述文件名确定路由类型,并根据所述路由类型和所述文件名生成第二路由数据;If there is a sub-routing file, then step D is performed to obtain the file name of the currently traversed sub-routing file, determine the routing type according to the file name, and generate second routing data according to the routing type and the file name;
若当前遍历的页面目录所对应的文件夹中存在子路由文件,则获取当前遍历的子路由文件的文件名,根据文件名确定路由类型。具体的,在确定路由类型时,若检测到文件名中包括index.vue,则确定路由类型为默认路由;若检测到文件名中包括@这一特殊字符,则确定路由类型为动态路由;若检测到文件名中包括*.vue,则确定路由类型为模糊匹配;若检测到文件名中仅包括.vue,则确定路由类型为常规路由。然后,根据路由类型和文件名生成第二路由数据。其中,第二路由数据至少包括路由路径信息、组件信息,还可以包括路由名称、meta标签和父子关系信息等。If a sub-routing file exists in the folder corresponding to the currently traversed page directory, the file name of the currently traversed sub-routing file is obtained, and the routing type is determined according to the file name. Specifically, when determining the routing type, if it is detected that the file name includes index.vue, the routing type is determined to be the default routing; if the special character @ is detected in the file name, the routing type is determined to be dynamic routing; if If it is detected that the file name includes *.vue, the route type is determined to be fuzzy matching; if it is detected that the file name only includes .vue, the route type is determined to be a regular route. Then, the second routing data is generated according to the routing type and the file name. The second routing data includes at least routing path information and component information, and may also include routing names, meta tags, parent-child relationship information, and the like.
进一步地,若当前遍历的页面目录所对应的文件夹中存在子路由文件,则继续遍历当前遍历的页面目录的下一目录。Further, if there is a sub-routing file in the folder corresponding to the currently traversed page directory, continue to traverse the next directory of the currently traversed page directory.
步骤E,获取所述子路由文件对应的布局文件及其第一路由数据,并根据所述第二路由数据对所述第一路由数据进行更新;Step E, acquiring the layout file corresponding to the sub-routing file and its first routing data, and updating the first routing data according to the second routing data;
在检测到存在子路由文件后,获取子路由文件对应的布局文件及其第一路由数据,并根据第二路由数据对第一路由数据进行更新。需要说明的是,步骤D和步骤E的执行顺序不分先后。After detecting the existence of the sub-routing file, acquire the layout file corresponding to the sub-routing file and its first routing data, and update the first routing data according to the second routing data. It should be noted that the execution order of step D and step E is not in any particular order.
具体的,步骤E包括:Specifically, step E includes:
步骤E1,检测当前遍历的页面目录所对应的文件夹中是否存在布局文件;Step E1, detecting whether there is a layout file in the folder corresponding to the currently traversed page directory;
若当前遍历的页面目录所对应的文件夹中存在布局文件,则执行步骤E21,确定当前遍历的页面目录所对应的文件夹中的布局文件为所述子路由文件对应的布局路由;If there is a layout file in the folder corresponding to the currently traversed page directory, step E21 is executed to determine that the layout file in the folder corresponding to the currently traversed page directory is the layout route corresponding to the sub-routing file;
若当前遍历的页面目录所对应的文件夹中不存在布局文件,则执行步骤E22,检测当前遍历的页面目录的上级目录中是否存在对应的布局路由;If there is no layout file in the folder corresponding to the currently traversed page directory, step E22 is performed to detect whether there is a corresponding layout route in the upper-level directory of the currently traversed page directory;
若当前遍历的页面目录的上级目录中存在对应的布局路由,则执行步骤E23确定所述当前遍历的页面目录的上级目录中的布局路由为所述子路由文件对应的布局路由;If there is a corresponding layout route in the upper-level directory of the currently traversed page directory, then perform step E23 to determine that the layout route in the upper-level directory of the currently traversed page directory is the layout route corresponding to the sub-routing file;
进一步地,在上述步骤E21和E23之后,还包括:Further, after the above steps E21 and E23, it also includes:
步骤E3,获取所述布局路由的第一路由数据,并根据所述第二路由数据更新所述对应的布局路由的第一路由数据。Step E3: Acquire the first routing data of the layout route, and update the first routing data of the corresponding layout route according to the second routing data.
在本实施例中,在检测当前遍历的页面目录所对应的文件夹中是否存在子路由文件的同时,可通过node.js提供的readdirSync函数遍历页面目录,检测当前遍历的页面目录所对应的文件夹中是否存在布局文件,具体的,可通过检测文件夹中的文件后缀是否存在layout.vue,来检测是否存在布局文件。In this embodiment, while detecting whether there is a sub-routing file in the folder corresponding to the currently traversed page directory, the readdirSync function provided by node.js can be used to traverse the page directory to detect the file corresponding to the currently traversed page directory Whether there is a layout file in the folder, specifically, by detecting whether the file suffix in the folder exists layout.vue, to detect whether there is a layout file.
若当前遍历的页面目录所对应的文件夹中存在布局文件,则确定当前遍历的页面目录所对应的文件夹中的布局文件为子路由文件对应的布局路由(即父路由);若当前遍历的页面目录所对应的文件夹中不存在布局文件,则检测当前遍历的页面目录的上级目录中是否存在对应的布局路由,若当前遍历的页面目录的上级目录中存在对应的布局路由,则确定当前遍历的页面目录的上级目录中的布局路由为子路由文件对应的布局路由。If there is a layout file in the folder corresponding to the currently traversed page directory, determine that the layout file in the folder corresponding to the currently traversed page directory is the layout route (that is, the parent route) corresponding to the child routing file; If there is no layout file in the folder corresponding to the page directory, check whether there is a corresponding layout route in the parent directory of the currently traversed page directory. If there is a corresponding layout route in the parent directory of the currently traversed page directory, determine the current The layout route in the parent directory of the traversed page directory is the layout route corresponding to the child route file.
然后,获取布局路由的第一路由数据。其中,第一路由数据至少包括路由路径信息、组件信息,还可以包括路由名称、meta标签和父子关系信息等。其中,布局路由的路由路径信息,是根据文件相对于src/pages目录的路径地址、再去掉文件后缀得到的,此外,需要对文件名中的特殊字符进行替换,得到符合预设代码规范的路由路径信息,以便于后续根据替换后的路由路径信息解析得到待跳转页面地址url,例如,将动态路由的“@”替换成“:”,将默认路由中“/index”替换成“/”,将父路由中“/layout”替换成“/”。组件(component)信息,则是路由对应的组件的信息,其为文件的绝对路径。路由名称name,是根据文件相对于pages目录的路径地址,name后续会作为代码中的变量,用于解析待跳转页面地址url,也需要符合预设代码规范,所以也需要对一些特殊字符进行替换,例如,将动态路由的“@”替换成“_”,去掉文件后缀,再把“/”转换成“_”。meta标签可用于标注路由是否需要登录、状态标签等一些额外信息。父子关系信息则是父路由和子路由之间的关系。Then, the first routing data of the layout routing is acquired. The first routing data includes at least routing path information and component information, and may also include routing names, meta tags, parent-child relationship information, and the like. Among them, the routing path information of the layout routing is obtained according to the path address of the file relative to the src/pages directory, and then removing the file suffix. In addition, special characters in the file name need to be replaced to obtain a route that conforms to the preset code specification. Path information, so that the URL of the page to be jumped can be obtained by subsequent analysis according to the replaced routing path information. For example, replace "@" in dynamic routing with ":", and replace "/index" in default routing with "/" , and replace "/layout" in the parent route with "/". The component information is the information of the component corresponding to the route, which is the absolute path of the file. The route name name is based on the path address of the file relative to the pages directory. Name will be used as a variable in the code to resolve the URL of the page to be jumped. It also needs to conform to the preset code specification, so some special characters also need to be specified. Substitution, for example, replace "@" in dynamic routing with "_", remove the file suffix, and then convert "/" into "_". The meta tag can be used to mark whether the route needs some additional information such as login, status tag, etc. The parent-child relationship information is the relationship between the parent route and the child route.
在获取到布局路由的第一路由数据后,根据第二路由数据更新对应的布局路由的第一路由数据。具体的,将第二路由数据推入布局路由(即父路由)的children(子节点)属性中,以更新父路由的父子关系信息。After the first routing data of the layout route is acquired, the first routing data of the corresponding layout route is updated according to the second routing data. Specifically, the second routing data is pushed into the children (child node) attribute of the layout routing (that is, the parent routing), so as to update the parent-child relationship information of the parent routing.
进一步地,在上述步骤E之后,还包括:Further, after the above step E, it also includes:
步骤F,根据更新后的第一路由数据和所述第二路由数据生成所述路由配置文件。Step F: Generate the routing configuration file according to the updated first routing data and the second routing data.
最后,根据更新后的第一路由数据和第二路由数据生成路由配置文件。Finally, a routing configuration file is generated according to the updated first routing data and the second routing data.
具体的,步骤F包括:Specifically, step F includes:
步骤F1,对更新后的第一路由数据和所述第二路由数据执行预设模板,生成各路由的依赖引入逻辑;Step F1, executing a preset template on the updated first routing data and the second routing data, and generating the dependency import logic of each route;
步骤F2,将所述依赖引入逻辑写入预设路由配置模板中,得到初始路由配置文件;Step F2, writing the dependency import logic into a preset routing configuration template to obtain an initial routing configuration file;
步骤F3,对所述初始路由配置文件进行编译,得到所述路由配置文件。Step F3: Compile the initial routing configuration file to obtain the routing configuration file.
本实施例中,在解析得到路由的配置(即更新后的第一路由数据和第二路由数据)之后,可先创建一个空数组结构的容器Root,将其置于一个空数组结构的容器Root(根)中,进而按照JavaScript语法规范,构造路由配置文件(route.config.js)的代码。In this embodiment, after the configuration of the route (that is, the updated first routing data and the second routing data) is obtained by parsing, a container Root with an empty array structure may be created first and placed in a container Root with an empty array structure (root), and then construct the code of the routing configuration file (route.config.js) according to the JavaScript syntax specification.
具体的,先对更新后的第一路由数据和第二路由数据执行预设模板,生成各路由的依赖引入逻辑,其中,预设模板在一实施例中为“import {{name}} from '{{component}}';”,可递归遍历Root容器,对Root容器中每个路由项执行一次模板,生成每个路由的依赖引入(import)逻辑。即,通过执行预设模板获取路由对应的路由数据中的组件名称和路由文件地址(即路由路径信息),然后将预设模板中的{{name}}替换为组件名称,并将预设模板中的{{component}}替换为路由文件地址,进而得到路由的依赖引入逻辑。例如,“pages/a.vue”组件的依赖引入逻辑代码是“import a from ‘project/src/pages/a.vue’”,然后写入route.config.js头部。然后,将所述依赖引入逻辑写入预设路由配置模板中,得到初始路由配置文件。Specifically, a preset template is first executed on the updated first routing data and the second routing data, and the dependency import logic of each route is generated, wherein the preset template is "import {{name}} from ' in one embodiment. {{component}}';", which can recursively traverse the Root container, execute a template for each route item in the Root container, and generate the import logic for each route. That is, the component name and routing file address (that is, routing path information) in the routing data corresponding to the route are obtained by executing the preset template, then {{name}} in the preset template is replaced with the component name, and the preset template Replace the {{component}} in the route file address with the route's dependency import logic. For example, the dependency import logic code of the "pages/a.vue" component is "import a from 'project/src/pages/a.vue'", and then written to the route.config.js header. Then, the dependency introduction logic is written into a preset routing configuration template to obtain an initial routing configuration file.
由于初始路由配置文件无法被浏览器直接运行,因此,还需对初始路由配置文件进行编译,得到路由配置文件。在编译时,可通过webpack(模块打包器)进行编译。Since the initial routing configuration file cannot be directly run by the browser, it is also necessary to compile the initial routing configuration file to obtain the routing configuration file. At compile time, it can be compiled via webpack (module bundler).
此外,需要说明的是,在具体实施例,上述步骤A-F可在开发者端中的执行。In addition, it should be noted that, in a specific embodiment, the above steps A-F may be executed on the developer end.
通过上述方式,可实现路由配置文件的智能生成,无需开发者每次手动编写路由配置,可节省开发时间和成本,提高路由配置文件的配置效率。Through the above method, the intelligent generation of the routing configuration file can be realized, and the developer does not need to manually write the routing configuration every time, which can save development time and cost, and improve the configuration efficiency of the routing configuration file.
进一步地,基于上述第一实施例,提出本申请页面渲染方法的第三实施例。Further, based on the above-mentioned first embodiment, a third embodiment of the page rendering method of the present application is proposed.
在本实施例中,在上述步骤“加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面”之前,该页面渲染方法还包括:In this embodiment, before the above step "loading the target component to render the target page corresponding to the address of the page to be jumped", the page rendering method further includes:
步骤G,获取用户预先编写的单文件组件,对所述单文件组件进行编译;Step G, obtaining the single-file component pre-written by the user, and compiling the single-file component;
在本实施例中,由于在Vue项目中,有一种代码组织方式叫做“.vue单文件组件”,在单文件组件中可编写html模板、js逻辑和css样式,用于后续被加载以显示待跳转页面。然而,单文件组件无法被浏览器直接运行,因此,需先获取用户预先编写的单文件组件,对该单文件组件进行编译,以使得浏览器可直接运行。具体的,在编译时,可通过webpack(模块打包器)进行编译。webpack的主要目标是将JavaScript文件打包在一起,打包后的文件用于在浏览器中使用。In this embodiment, because there is a code organization method called ".vue single-file component" in the Vue project, html templates, js logic and css styles can be written in the single-file component for subsequent loading to display the pending Jump page. However, the single-file component cannot be directly run by the browser. Therefore, it is necessary to obtain the single-file component pre-written by the user and compile the single-file component, so that the browser can run it directly. Specifically, when compiling, it can be compiled through webpack (module bundler). The main goal of webpack is to bundle JavaScript files together for use in the browser.
此时,步骤“加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面”包括:At this time, the step of "loading the target component to render the target page corresponding to the address of the page to be jumped" includes:
进而,在确定目标组件之后,从编译后的单文件组件中加载目标组件,以渲染得到待跳转页面地址对应的目标页面。具体的加载渲染过程可参照其他实施例。Furthermore, after the target component is determined, the target component is loaded from the compiled single-file component to render the target page corresponding to the address of the page to be jumped. For the specific loading and rendering process, reference may be made to other embodiments.
此处,需要说明的是,步骤G的执行可与上述步骤F3的执行同时进行。可在开发人员输入完成后,获取输入的页面目录和单文件组件,进而根据页面目录生成初始路由配置文件,并进行编译,同时对单文件组件进行编译。还需要说明的是,在具体实施时,上述过程还可以在开发者端中执行,进而直接传输给前端服务器中的路由处理器。Here, it should be noted that the execution of step G may be performed simultaneously with the execution of the above-mentioned step F3. After the developer's input is completed, the input page directory and single-file component can be obtained, and then the initial routing configuration file can be generated according to the page directory and compiled, and the single-file component can be compiled at the same time. It should also be noted that, during specific implementation, the above process may also be executed on the developer side, and then directly transmitted to the routing processor in the front-end server.
进一步地,在基于后台框架SpringMVC实现页面跳转的过程中,每次跳转浏览器页面,都需要返回给浏览器完整的HTML(超文本标记语言)数据,从而导致页面跳转速度较慢。但是其实大部分应用都有固定的内容,如头部导航栏、菜单等,跳转浏览器页面时实际上只需要更新局部内容,对此,基于上述第一实施例,提出本申请页面渲染方法的第四实施例。Further, in the process of implementing page jumping based on the background framework SpringMVC, every time a browser page is jumped, complete HTML (Hypertext Markup Language) data needs to be returned to the browser, resulting in a slower page jumping speed. However, in fact, most applications have fixed content, such as the header navigation bar, menu, etc. In fact, only the partial content needs to be updated when jumping the browser page. In this regard, based on the above-mentioned first embodiment, the page rendering method of the present application is proposed. the fourth embodiment.
在本实施例中,步骤S40包括:In this embodiment, step S40 includes:
步骤a41,获取当前页面地址对应的当前路由路径,并获取所述目标路由的目标路由路径;Step a41, obtain the current routing path corresponding to the current page address, and obtain the target routing path of the target route;
在本实施例中,在确定目标路由之后,可先获取当前页面地址对应的当前路由路径,并获取目标路由的目标路由路径。即,先获取当前页面地址对应的当前路由,进而获取当前路由的路由路径,记为当前路由路径。In this embodiment, after the target route is determined, the current routing path corresponding to the current page address may be obtained first, and the target routing path of the target route may be obtained. That is, the current route corresponding to the current page address is obtained first, and then the routing path of the current route is obtained, which is recorded as the current routing path.
步骤a42,对所述当前路由路径进行拆分,得到第一子项数组,并对所述目标路由路径进行拆分,得到第二子项数组;Step a42, splitting the current routing path to obtain a first sub-item array, and splitting the target routing path to obtain a second sub-item array;
然后,对当前路由路径进行拆分,得到第一子项数组,并对目标路由路径进行拆分,得到第二子项数组。其中,路由路径的拆分过程中,可根据“/”这一字符对匹配路由路径进行拆分,按照拆分得到的子项的顺序对各子项进行标号,得到子项数组。例如,当前路由路径为/user/a,则拆分得到第一子项数组为:a[0]=user、a[1]=a。目标路由路径为/user/b,则拆分得到第二子项数组为:b[0]=user、b[1]=b。Then, the current routing path is split to obtain the first sub-item array, and the target routing path is split to obtain the second sub-item array. Among them, in the splitting process of the routing path, the matching routing path can be split according to the character "/", and the sub-items are labeled according to the order of the split-obtained sub-items to obtain a sub-item array. For example, if the current routing path is /user/a, the first sub-item array obtained by splitting is: a[0]=user, a[1]=a. If the target routing path is /user/b, then the second sub-item array obtained by splitting is: b[0]=user, b[1]=b.
步骤a43,将所述第一子项数组与所述第二子项数组进行比对,得到公共路由路径和非公共路由路径,并根据所述非公共路由路径确定目标组件;Step a43, compare the first sub-item array with the second sub-item array, obtain a public routing path and a non-public routing path, and determine a target component according to the non-public routing path;
将第一子项数组与第二子项数组进行比对,从而可得到公共路由路径和非公共路由路径。具体的比对方式为:按数组标号从小到大的顺序,判断同一标号的第一子项数组和第二子项数组是否相等,即,若第一子项数组为a[]、第二子项数组为b[],从标号0开始,先判断判断a[0]是否等于b[0],若相等,则继续判断a[1]是否等于b[1],依次类推,直到a[n]和b[n]不相等,相等的部分则是当前路由路径和目标路由路径公共的路径,记为公共路由路径,而非公共路由路径则为目标路由路径与当前路由路径不同的部分、即目标路由路径除公共路由路径外的部分。此处,需要说明的是,若a[0]不等于b[0],则确定公共路由路径为根路由路径,即为根端“/”。The first sub-item array is compared with the second sub-item array, so that the public routing path and the non-public routing path can be obtained. The specific comparison method is: according to the order of the array labels from small to large, judge whether the first sub-item array and the second sub-item array of the same label are equal, that is, if the first sub-item array is a[], the second sub-item array is equal to The item array is b[], starting from label 0, first judge whether a[0] is equal to b[0], if so, continue to judge whether a[1] is equal to b[1], and so on, until a[n] ] and b[n] are not equal, the equal part is the path common to the current routing path and the target routing path, which is recorded as the common routing path, and the non-public routing path is the part of the target routing path that is different from the current routing path, that is The part of the destination routing path excluding the public routing path. Here, it should be noted that if a[0] is not equal to b[0], it is determined that the common routing path is the root routing path, that is, the root end "/".
进而,根据非公共路由路径确定目标组件。即,根据非公共路由路径和路由配置文件,确定目标组件。Further, target components are determined based on non-public routing paths. That is, target components are determined based on non-public routing paths and routing profiles.
步骤a44,根据所述公共路由路径确定公共路由组件,卸载所述当前路由路径对应的当前路由组件中除所述公共路由组件外的组件,并加载所述目标组件。Step a44: Determine a common routing component according to the common routing path, unload components other than the common routing component in the current routing components corresponding to the current routing path, and load the target component.
最后,根据公共路由路径确定公共路由组件,卸载当前路由路径对应的当前路由组件中除公共路由组件外的组件,并加载目标组件。Finally, the common routing component is determined according to the common routing path, the components except the common routing component in the current routing components corresponding to the current routing path are unloaded, and the target component is loaded.
即,在具体实施时,假设当前浏览器页面/user/a和待跳转页面/user/b有相同部分,如头部导航栏和左侧菜单栏,则可以把相同部分内容设计为父路由/user,然后页面/user/a和页面/user/b分别包含差异部分内容(如分别对应组件A和B),则将路由/user/a和路由/user/b作为父路由的子路由,在从/user/a切换到/user/b时,可确定目标组件为B,此时,卸载A后加载B即可。That is, in the specific implementation, assuming that the current browser page /user/a and the page to be jumped /user/b have the same part, such as the header navigation bar and the left menu bar, the same part of the content can be designed as the parent route /user, then the page /user/a and page /user/b contain different content respectively (for example, corresponding to components A and B respectively), then route /user/a and route /user/b are used as child routes of the parent route, When switching from /user/a to /user/b, it can be determined that the target component is B. In this case, load B after unloading A.
本实施例中,通过对比当前路由路径和目标路由路径,找到最近的父路由(即公共路由路径对应的路由),再以最小化更新原则卸载老组件(即当前路由组件中除公共路由组件外的组件),加载新组件(即目标组件),显示待跳转页面。通过上述方式,在浏览器页面跳转时,可无需对固定内容部分进行更新,从而可以避免重复内容的更新,从而可进一步地提高页面跳转速度,提升用户的使用体验。In this embodiment, by comparing the current routing path and the target routing path, find the nearest parent route (that is, the route corresponding to the public routing path), and then uninstall the old component (that is, the current routing component except the public routing component) based on the principle of minimizing the update. component), load the new component (that is, the target component), and display the page to be jumped. In the above manner, when the browser page jumps, it is not necessary to update the fixed content part, thereby avoiding the updating of repeated content, thereby further improving the page jumping speed and improving the user experience.
本申请还提供一种页面渲染装置。The present application also provides a page rendering apparatus.
参照图3,图3为本申请页面渲染装置第一实施例的功能模块示意图。Referring to FIG. 3 , FIG. 3 is a schematic diagram of functional modules of the first embodiment of the page rendering apparatus of the present application.
如图3所示,所述页面渲染装置包括:As shown in Figure 3, the page rendering apparatus includes:
第一获取模块10,用于在接收到浏览器页面跳转请求时,根据所述浏览器页面跳转请求获取待跳转页面地址;The first obtaining module 10 is configured to, when receiving a browser page jump request, obtain the address of the page to be jumped according to the browser page jump request;
第二获取模块20,用于从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径;A second obtaining module 20, configured to obtain a route matching the address of the page to be jumped from a pre-generated routing configuration file, and obtain a matching routing path of the matching route;
路由评分模块30,用于根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由;The route scoring module 30 is used for scoring each matched route according to the matching routing path, and determining the target route according to the scoring result;
页面渲染模块40,用于根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面。The page rendering module 40 is configured to determine the target component corresponding to the target route according to the routing configuration file, and load the target component to render the target page corresponding to the address of the page to be jumped.
进一步地,所述路由评分模块30包括:Further, the route scoring module 30 includes:
第一计算单元,用于对所述匹配路由路径进行拆分,得到各相匹配的路由的子项数量,根据所述子项数量和第一预设分值计算得到第一得分;a first calculation unit, configured to split the matching routing path, obtain the number of sub-items of each matching route, and calculate and obtain a first score according to the number of sub-items and a first preset score;
第一确定单元,用于获取各相匹配的路由的各子项的子项类型,并根据所述子项类型确定各相匹配的路由的各子项的第二得分;a first determining unit, configured to obtain the sub-item type of each sub-item of each matched route, and determine the second score of each sub-item of each matched route according to the sub-item type;
第二计算单元,用于对所述第一得分和所述第二得分进行加和,得到各相匹配的路由的评分;A second computing unit, configured to add the first score and the second score to obtain the scores of each matching route;
第二确定单元,用于将所述评分中最大值所对应的路由确定为目标路由。The second determining unit is configured to determine the route corresponding to the maximum value in the score as the target route.
进一步地,所述第一确定单元,具体用于:Further, the first determining unit is specifically used for:
检测各相匹配的路由的各子项中是否包括预设特殊字符,得到第一检测结果;Detecting whether each sub-item of each matching route includes preset special characters, and obtaining a first detection result;
检测各相匹配的路由的各子项是否为根端,得到第二检测结果;Detecting whether each sub-item of each matching route is the root end, and obtaining a second detection result;
根据所述第一检测结果和所述第二检测结果确定各子项的子项类型;Determine the sub-item type of each sub-item according to the first detection result and the second detection result;
根据所述子项类型和预设子项类型与分值之间的映射关系,确定各相匹配的路由的各子项的第二得分。The second score of each sub-item of each matching route is determined according to the sub-item type and the mapping relationship between the preset sub-item type and the score.
进一步地,所述页面渲染装置还包括:Further, the page rendering apparatus further includes:
界面显示模块,用于在接收到路由设置请求时,根据所述路由设置请求显示页面目录设置界面;an interface display module, configured to display a page directory setting interface according to the route setting request when receiving the route setting request;
第三获取模块,用于在接收到用户基于所述页面目录设置界面触发的输入完成指令时,获取用户输入的页面目录;a third acquiring module, configured to acquire the page directory input by the user when receiving an input completion instruction triggered by the user based on the page directory setting interface;
第一检测模块,用于遍历所述页面目录,检测当前遍历的页面目录所对应的文件夹中是否存在子路由文件;The first detection module is used to traverse the page directory and detect whether there is a sub-routing file in the folder corresponding to the currently traversed page directory;
第四获取模块,用于若存在子路由文件,则获取当前遍历的子路由文件的文件名,根据所述文件名确定路由类型,并根据所述路由类型和所述文件名生成第二路由数据;The fourth obtaining module is used to obtain the file name of the currently traversed sub-routing file if there is a sub-routing file, determine the routing type according to the file name, and generate the second routing data according to the routing type and the file name ;
数据更新模块,用于获取所述子路由文件对应的布局文件及其第一路由数据,并根据所述第二路由数据对所述第一路由数据进行更新;a data update module, configured to obtain the layout file corresponding to the sub-routing file and its first routing data, and update the first routing data according to the second routing data;
文件生成模块,用于根据更新后的第一路由数据和所述第二路由数据生成所述路由配置文件。A file generation module, configured to generate the routing configuration file according to the updated first routing data and the second routing data.
进一步地,所述数据更新模块包括:Further, the data update module includes:
第一检测单元,用于检测当前遍历的页面目录所对应的文件夹中是否存在布局文件;The first detection unit is used to detect whether there is a layout file in the folder corresponding to the currently traversed page directory;
第三确定单元,用于若当前遍历的页面目录所对应的文件夹中存在布局文件,则确定当前遍历的页面目录所对应的文件夹中的布局文件为所述子路由文件对应的布局路由;A third determining unit, configured to determine that the layout file in the folder corresponding to the currently traversed page directory is the layout route corresponding to the sub-routing file if there is a layout file in the folder corresponding to the currently traversed page directory;
第二检测单元,用于若当前遍历的页面目录所对应的文件夹中不存在布局文件,则检测当前遍历的页面目录的上级目录中是否存在对应的布局路由;The second detection unit is configured to detect whether there is a corresponding layout route in the upper-level directory of the currently traversed page directory if there is no layout file in the folder corresponding to the currently traversed page directory;
第四确定单元,用于若当前遍历的页面目录的上级目录中存在对应的布局路由,则确定所述当前遍历的页面目录的上级目录中的布局路由为所述子路由文件对应的布局路由;The fourth determining unit is configured to determine that the layout route in the upper-level directory of the currently traversed page directory is the layout route corresponding to the sub-routing file if there is a corresponding layout route in the upper-level directory of the currently traversed page directory;
数据更新单元,用于获取所述布局路由的第一路由数据,并根据所述第二路由数据更新所述对应的布局路由的第一路由数据。A data updating unit, configured to acquire the first routing data of the layout route, and update the first routing data of the corresponding layout route according to the second routing data.
进一步地,所述文件生成模块包括:Further, the file generation module includes:
模板执行单元,用于对更新后的第一路由数据和所述第二路由数据执行预设模板,生成各路由的依赖引入逻辑;a template execution unit, configured to execute a preset template on the updated first routing data and the second routing data, and generate dependency import logic for each route;
逻辑写入单元,用于将所述依赖引入逻辑写入预设路由配置模板中,得到初始路由配置文件;a logic writing unit, configured to write the dependency import logic into a preset routing configuration template to obtain an initial routing configuration file;
文件编译单元,用于对所述初始路由配置文件进行编译,得到所述路由配置文件。A file compiling unit, configured to compile the initial routing configuration file to obtain the routing configuration file.
进一步地,所述页面渲染模块40包括:Further, the page rendering module 40 includes:
第一获取单元,用于获取当前页面地址对应的当前路由路径,并获取所述目标路由的目标路由路径;The first obtaining unit is used to obtain the current routing path corresponding to the current page address, and obtain the target routing path of the target routing;
路径拆分单元,用于对所述当前路由路径进行拆分,得到第一子项数组,并对所述目标路由路径进行拆分,得到第二子项数组;a path splitting unit for splitting the current routing path to obtain a first sub-item array, and splitting the target routing path to obtain a second sub-item array;
数组比对单元,用于将所述第一子项数组与所述第二子项数组进行比对,得到公共路由路径和非公共路由路径,并根据所述非公共路由路径确定目标组件;an array comparison unit, configured to compare the first sub-item array with the second sub-item array to obtain a public routing path and a non-public routing path, and determine a target component according to the non-public routing path;
组件加载单元,用于根据所述公共路由路径确定公共路由组件,卸载所述当前路由路径对应的当前路由组件中除所述公共路由组件外的组件,并加载所述目标组件。A component loading unit, configured to determine a common routing component according to the common routing path, unload components other than the common routing component in the current routing components corresponding to the current routing path, and load the target component.
其中,上述页面渲染装置中各个模块的功能实现与上述页面渲染方法实施例中各步骤相对应,其功能和实现过程在此处不再一一赘述。The function implementation of each module in the above-mentioned page rendering apparatus corresponds to each step in the above-mentioned page rendering method embodiment, and the functions and implementation process thereof will not be repeated here.
本申请还提供一种计算机可读存储介质,该计算机可读存储介质上存储有页面渲染程序,所述页面渲染程序被处理器执行时实现如以上任一项实施例所述的页面渲染方法的步骤。The present application further provides a computer-readable storage medium, where a page rendering program is stored on the computer-readable storage medium, and when the page rendering program is executed by a processor, the page rendering method according to any one of the above embodiments is implemented. step.
本申请计算机可读存储介质的具体实施例与上述页面渲染方法各实施例基本相同,在此不作赘述。The specific embodiments of the computer-readable storage medium of the present application are basically the same as the above-mentioned embodiments of the page rendering method, and are not repeated here.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者系统中还存在另外的相同要素。It should be noted that, herein, the terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion, such that a process, method, article or system comprising a series of elements includes not only those elements, It also includes other elements not expressly listed or inherent to such a process, method, article or system. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, method, article or system that includes the element.
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The above-mentioned serial numbers of the embodiments of the present application are only for description, and do not represent the advantages or disadvantages of the embodiments.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本申请各个实施例所述的方法。From the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general hardware platform, and of course hardware can also be used, but in many cases the former is better implementation. Based on this understanding, the technical solutions of the present application can be embodied in the form of software products in essence or the parts that make contributions to the prior art. The computer software products are stored in a storage medium (such as ROM/RAM) as described above. , magnetic disk, optical disk), including several instructions to make a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) execute the methods described in the various embodiments of the present application.
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。The above are only the preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the contents of the description and drawings of the present application, or directly or indirectly applied in other related technical fields , are similarly included within the scope of patent protection of this application.

Claims (10)

  1. 一种页面渲染方法,其中,所述页面渲染方法包括:A page rendering method, wherein the page rendering method includes:
    在接收到浏览器页面跳转请求时,根据所述浏览器页面跳转请求获取待跳转页面地址;When receiving the browser page jump request, obtain the address of the page to be jumped according to the browser page jump request;
    从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径;Obtain a route matching the address of the page to be redirected from a pre-generated routing configuration file, and obtain a matching routing path of the matching route;
    根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由;Score each matching route according to the matching routing path, and determine the target route according to the scoring result;
    根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面。The target component corresponding to the target route is determined according to the routing configuration file, and the target component is loaded to render the target page corresponding to the address of the page to be redirected.
  2. 如权利要求1所述的页面渲染方法,其中,所述根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由的步骤包括:The page rendering method according to claim 1, wherein the step of scoring each matching route according to the matching routing path, and determining the target route according to the scoring result comprises:
    对所述匹配路由路径进行拆分,得到各相匹配的路由的子项数量,根据所述子项数量和第一预设分值计算得到第一得分;Splitting the matching routing path to obtain the number of sub-items of each matching route, and calculating the first score according to the number of sub-items and the first preset score;
    获取各相匹配的路由的各子项的子项类型,并根据所述子项类型确定各相匹配的路由的各子项的第二得分;Obtain the sub-item type of each sub-item of each matched route, and determine the second score of each sub-item of each matched route according to the sub-item type;
    对所述第一得分和所述第二得分进行加和,得到各相匹配的路由的评分;The first score and the second score are added to obtain the scores of each matching route;
    将所述评分中最大值所对应的路由确定为目标路由。The route corresponding to the maximum value in the scores is determined as the target route.
  3. 如权利要求2所述的页面渲染方法,其中,所述获取各相匹配的路由的各子项的子项类型,并根据所述子项类型确定各相匹配的路由的各子项的第二得分的步骤包括:The page rendering method according to claim 2, wherein the acquiring the sub-item type of each sub-item of each matching route, and determining the second sub-item of each sub-item of each matching route according to the sub-item type The steps for scoring include:
    检测各相匹配的路由的各子项中是否包括预设特殊字符,得到第一检测结果;Detecting whether each sub-item of each matching route includes preset special characters, and obtaining a first detection result;
    检测各相匹配的路由的各子项是否为根端,得到第二检测结果;Detecting whether each sub-item of each matching route is the root end, and obtaining a second detection result;
    根据所述第一检测结果和所述第二检测结果确定各子项的子项类型;Determine the sub-item type of each sub-item according to the first detection result and the second detection result;
    根据所述子项类型和预设子项类型与分值之间的映射关系,确定各相匹配的路由的各子项的第二得分。The second score of each sub-item of each matching route is determined according to the sub-item type and the mapping relationship between the preset sub-item type and the score.
  4. 如权利要求1至3中任一项所述的页面渲染方法,其中,所述从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径的步骤之前,还包括:The page rendering method according to any one of claims 1 to 3, wherein the route matching the address of the page to be jumped is obtained from a pre-generated route configuration file, and the matching route is obtained. Before the step of matching the routing path of the route, it also includes:
    在接收到路由设置请求时,根据所述路由设置请求显示页面目录设置界面;When receiving a routing setting request, display a page directory setting interface according to the routing setting request;
    在接收到用户基于所述页面目录设置界面触发的输入完成指令时,获取用户输入的页面目录;When receiving an input completion instruction triggered by the user based on the page directory setting interface, acquiring the page directory input by the user;
    遍历所述页面目录,检测当前遍历的页面目录所对应的文件夹中是否存在子路由文件;Traverse the page directory, and detect whether there is a sub-routing file in the folder corresponding to the currently traversed page directory;
    若存在子路由文件,则获取当前遍历的子路由文件的文件名,根据所述文件名确定路由类型,并根据所述路由类型和所述文件名生成第二路由数据;If there is a sub-routing file, obtain the file name of the currently traversed sub-routing file, determine the routing type according to the file name, and generate second routing data according to the routing type and the file name;
    获取所述子路由文件对应的布局文件及其第一路由数据,并根据所述第二路由数据对所述第一路由数据进行更新;Obtain the layout file corresponding to the sub-routing file and its first routing data, and update the first routing data according to the second routing data;
    根据更新后的第一路由数据和所述第二路由数据生成所述路由配置文件。The routing configuration file is generated according to the updated first routing data and the second routing data.
  5. 如权利要求4所述的页面渲染方法,其中,所述获取所述子路由文件对应的布局文件及其第一路由数据,并根据所述第二路由数据对所述第一路由数据进行更新的步骤包括:The page rendering method according to claim 4, wherein the method of acquiring a layout file corresponding to the sub-routing file and its first routing data, and updating the first routing data according to the second routing data Steps include:
    检测当前遍历的页面目录所对应的文件夹中是否存在布局文件;Detect whether there is a layout file in the folder corresponding to the currently traversed page directory;
    若当前遍历的页面目录所对应的文件夹中存在布局文件,则确定当前遍历的页面目录所对应的文件夹中的布局文件为所述子路由文件对应的布局路由;If there is a layout file in the folder corresponding to the currently traversed page directory, then determine that the layout file in the folder corresponding to the currently traversed page directory is the layout route corresponding to the sub-routing file;
    若当前遍历的页面目录所对应的文件夹中不存在布局文件,则检测当前遍历的页面目录的上级目录中是否存在对应的布局路由;If there is no layout file in the folder corresponding to the currently traversed page directory, detect whether there is a corresponding layout route in the upper-level directory of the currently traversed page directory;
    若当前遍历的页面目录的上级目录中存在对应的布局路由,则确定所述当前遍历的页面目录的上级目录中的布局路由为所述子路由文件对应的布局路由;If there is a corresponding layout route in the upper-level directory of the currently traversed page directory, then determine that the layout route in the upper-level directory of the currently traversed page directory is the layout route corresponding to the sub-routing file;
    获取所述布局路由的第一路由数据,并根据所述第二路由数据更新所述对应的布局路由的第一路由数据。The first routing data of the layout route is acquired, and the first routing data of the corresponding layout route is updated according to the second routing data.
  6. 如权利要求4所述的页面渲染方法,其中,所述根据更新后的第一路由数据和所述第二路由数据生成所述路由配置文件的步骤包括:The page rendering method according to claim 4, wherein the step of generating the routing configuration file according to the updated first routing data and the second routing data comprises:
    对更新后的第一路由数据和所述第二路由数据执行预设模板,生成各路由的依赖引入逻辑;Execute a preset template on the updated first routing data and the second routing data, and generate the dependency import logic of each route;
    将所述依赖引入逻辑写入预设路由配置模板中,得到初始路由配置文件;Writing the dependency import logic into a preset routing configuration template to obtain an initial routing configuration file;
    对所述初始路由配置文件进行编译,得到所述路由配置文件。The initial routing configuration file is compiled to obtain the routing configuration file.
  7. 如权利要求1至3中任一项所述的页面渲染方法,其中,所述根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面的步骤包括:The page rendering method according to any one of claims 1 to 3, wherein the target component corresponding to the target route is determined according to the routing configuration file, and the target component is loaded to render the to-be-hopped The steps of transferring the target page corresponding to the page address include:
    获取当前页面地址对应的当前路由路径,并获取所述目标路由的目标路由路径;Obtain the current routing path corresponding to the current page address, and obtain the target routing path of the target routing;
    对所述当前路由路径进行拆分,得到第一子项数组,并对所述目标路由路径进行拆分,得到第二子项数组;Splitting the current routing path to obtain a first sub-item array, and splitting the target routing path to obtain a second sub-item array;
    将所述第一子项数组与所述第二子项数组进行比对,得到公共路由路径和非公共路由路径,并根据所述非公共路由路径确定目标组件;Comparing the first sub-item array with the second sub-item array to obtain a public routing path and a non-public routing path, and determining a target component according to the non-public routing path;
    根据所述公共路由路径确定公共路由组件,卸载所述当前路由路径对应的当前路由组件中除所述公共路由组件外的组件,并加载所述目标组件。A common routing component is determined according to the common routing path, components other than the common routing component in the current routing components corresponding to the current routing path are unloaded, and the target component is loaded.
  8. 一种页面渲染装置,其中,所述页面渲染装置包括:A page rendering device, wherein the page rendering device includes:
    第一获取模块,用于在接收到浏览器页面跳转请求时,根据所述浏览器页面跳转请求获取待跳转页面地址;a first obtaining module, configured to obtain the address of the page to be jumped according to the browser page jump request when receiving the browser page jump request;
    第二获取模块,用于从预先生成的路由配置文件中获取与所述待跳转页面地址相匹配的路由,并获取所述相匹配的路由的匹配路由路径;A second obtaining module, configured to obtain a route matching the address of the page to be jumped from a pre-generated routing configuration file, and obtain a matching routing path of the matching route;
    路由评分模块,用于根据所述匹配路由路径对各相匹配的路由进行评分,并根据评分结果确定目标路由;A route scoring module, for scoring each matched route according to the matching routing path, and determining a target route according to the scoring result;
    页面渲染模块,用于根据所述路由配置文件确定所述目标路由对应的目标组件,加载所述目标组件,以渲染得到所述待跳转页面地址对应的目标页面。A page rendering module, configured to determine a target component corresponding to the target route according to the routing configuration file, and load the target component to render a target page corresponding to the address of the page to be jumped.
  9. 一种页面渲染设备,其中,所述页面渲染设备包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的页面渲染程序,所述页面渲染程序被所述处理器执行时实现如权利要求1至7中任一项所述的页面渲染方法的步骤。A page rendering device, wherein the page rendering device includes: a memory, a processor, and a page rendering program stored on the memory and executable on the processor, the page rendering program being executed by the processor The steps of implementing the page rendering method according to any one of claims 1 to 7 when executed.
  10. 一种计算机可读存储介质,其中,所述计算机可读存储介质上存储有页面渲染程序,所述页面渲染程序被处理器执行时实现如权利要求1至7中任一项所述的页面渲染方法的步骤。A computer-readable storage medium, wherein a page rendering program is stored on the computer-readable storage medium, and when the page rendering program is executed by a processor, the page rendering according to any one of claims 1 to 7 is realized steps of the method.
PCT/CN2021/085841 2020-08-12 2021-04-07 Page rendering method, apparatus, and device, and computer readable storage medium WO2022033055A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010809562.6A CN111949351B (en) 2020-08-12 2020-08-12 Page rendering method, device, equipment and computer readable storage medium
CN202010809562.6 2020-08-12

Publications (1)

Publication Number Publication Date
WO2022033055A1 true WO2022033055A1 (en) 2022-02-17

Family

ID=73333299

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/085841 WO2022033055A1 (en) 2020-08-12 2021-04-07 Page rendering method, apparatus, and device, and computer readable storage medium

Country Status (2)

Country Link
CN (1) CN111949351B (en)
WO (1) WO2022033055A1 (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114528063A (en) * 2022-04-21 2022-05-24 苏州万店掌网络科技有限公司 Page display method, device, equipment and storage medium
CN115268914A (en) * 2022-08-09 2022-11-01 华润数字科技有限公司 Micro front-end page generation method, device, equipment and medium based on modularization
CN116149757A (en) * 2023-04-14 2023-05-23 深圳复临科技有限公司 Plug-in virtual route realization method, device, computer equipment and storage medium
CN116595285A (en) * 2023-07-19 2023-08-15 深圳复临科技有限公司 Route generation method, device, computer equipment and storage medium
CN117112021A (en) * 2023-10-24 2023-11-24 腾讯科技(深圳)有限公司 Route configuration generation method, device, equipment and computer readable storage medium
CN117312694A (en) * 2023-11-29 2023-12-29 深圳市纷享互联科技有限责任公司 Method, device and storage medium for constructing H5 application based on applet framework

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111949351B (en) * 2020-08-12 2023-04-07 深圳前海微众银行股份有限公司 Page rendering method, device, equipment and computer readable storage medium
CN112380480A (en) * 2020-12-02 2021-02-19 北京皮尔布莱尼软件有限公司 Page jump method, computing device and storage medium
CN112732742B (en) * 2021-01-12 2023-03-28 深圳平安医疗健康科技服务有限公司 Query page creating method and device, computer equipment and storage medium
CN112988260B (en) * 2021-01-25 2023-07-04 杭州衣科云科技有限公司 Application cold start optimization method and device, computer equipment and storage medium
CN113254100B (en) * 2021-05-25 2023-08-01 四川虹魔方网络科技有限公司 Method for realizing dynamic loading of multistage route based on Vue
CN114253650A (en) * 2021-12-27 2022-03-29 中国农业银行股份有限公司 Display component transition method, device, equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107968841A (en) * 2017-12-20 2018-04-27 深圳乐信软件技术有限公司 Dynamic routing method, device, storage medium and the client of Webpage
CN110347942A (en) * 2019-05-31 2019-10-18 深圳壹账通智能科技有限公司 Method for page jump, device, storage medium and computer equipment
CN110515683A (en) * 2019-07-15 2019-11-29 平安普惠企业管理有限公司 A kind of method, apparatus and storage medium of front end Vue page visual configuration
US20200177665A1 (en) * 2015-11-27 2020-06-04 Alibaba Group Holding Limited Page jump method and apparatus
CN111949351A (en) * 2020-08-12 2020-11-17 深圳前海微众银行股份有限公司 Page rendering method, device, equipment and computer readable storage medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8880397B2 (en) * 2011-10-21 2014-11-04 Wal-Mart Stores, Inc. Systems, devices and methods for list display and management
CN103685611A (en) * 2013-12-31 2014-03-26 山石网科通信技术有限公司 Network access processing method and device
CN105589914B (en) * 2015-07-20 2018-07-06 广州市动景计算机科技有限公司 A kind of pre-reading method of Webpage, device and intelligent terminal
CN106610994A (en) * 2015-10-23 2017-05-03 北京国双科技有限公司 Method and device for counting click paths

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200177665A1 (en) * 2015-11-27 2020-06-04 Alibaba Group Holding Limited Page jump method and apparatus
CN107968841A (en) * 2017-12-20 2018-04-27 深圳乐信软件技术有限公司 Dynamic routing method, device, storage medium and the client of Webpage
CN110347942A (en) * 2019-05-31 2019-10-18 深圳壹账通智能科技有限公司 Method for page jump, device, storage medium and computer equipment
CN110515683A (en) * 2019-07-15 2019-11-29 平安普惠企业管理有限公司 A kind of method, apparatus and storage medium of front end Vue page visual configuration
CN111949351A (en) * 2020-08-12 2020-11-17 深圳前海微众银行股份有限公司 Page rendering method, device, equipment and computer readable storage medium

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114528063A (en) * 2022-04-21 2022-05-24 苏州万店掌网络科技有限公司 Page display method, device, equipment and storage medium
CN115268914A (en) * 2022-08-09 2022-11-01 华润数字科技有限公司 Micro front-end page generation method, device, equipment and medium based on modularization
CN116149757A (en) * 2023-04-14 2023-05-23 深圳复临科技有限公司 Plug-in virtual route realization method, device, computer equipment and storage medium
CN116149757B (en) * 2023-04-14 2023-06-30 深圳复临科技有限公司 Plug-in virtual route realization method, device, computer equipment and storage medium
CN116595285A (en) * 2023-07-19 2023-08-15 深圳复临科技有限公司 Route generation method, device, computer equipment and storage medium
CN116595285B (en) * 2023-07-19 2024-04-16 深圳复临科技有限公司 Route generation method, device, computer equipment and storage medium
CN117112021A (en) * 2023-10-24 2023-11-24 腾讯科技(深圳)有限公司 Route configuration generation method, device, equipment and computer readable storage medium
CN117112021B (en) * 2023-10-24 2024-01-26 腾讯科技(深圳)有限公司 Route configuration generation method, device, equipment and computer readable storage medium
CN117312694A (en) * 2023-11-29 2023-12-29 深圳市纷享互联科技有限责任公司 Method, device and storage medium for constructing H5 application based on applet framework
CN117312694B (en) * 2023-11-29 2024-02-02 深圳市纷享互联科技有限责任公司 Method, device and storage medium for constructing H5 application based on applet framework

Also Published As

Publication number Publication date
CN111949351A (en) 2020-11-17
CN111949351B (en) 2023-04-07

Similar Documents

Publication Publication Date Title
WO2022033055A1 (en) Page rendering method, apparatus, and device, and computer readable storage medium
US7185271B2 (en) Methods and systems for implementing auto-complete in a web page
JP5863214B2 (en) Storage of web browsing calculations with DOM-based isomorphism
US20130191439A1 (en) Managing script file dependencies and load times
US9311303B2 (en) Interpreted language translation system and method
US9141344B2 (en) Hover help support for application source code
US10133766B2 (en) Accessing and editing virtually-indexed message flows using structured query langauge (SQL)
US20130124969A1 (en) Xml editor within a wysiwyg application
CN112148356A (en) Document generation method, interface development method, device, server and storage medium
CN116560683A (en) Software updating method, device, equipment and storage medium
US20220171918A1 (en) User interface for managing extended schemas
US11568019B2 (en) Automation system and method
US20240095298A1 (en) Systems and methods for rendering interactive web pages
US11803609B2 (en) Method and system for navigation control to select a target page from possible target pages
WO2021120913A1 (en) Application loading method, device, user terminal and server
CN115687075A (en) Error correction method and device for page test script
CN110737642A (en) Database information analysis method, database information analysis device, computer device and storage medium
CN116243961A (en) Version file processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21855111

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21855111

Country of ref document: EP

Kind code of ref document: A1