• Are there any additional rules for routing custom routes?
    I have read and tried create-custom-route-in-plugin to add /api route but it still didn't work when link is not opened but clicked on another page.
    Maybe someone has a full example of this routing

  • Global Moderator

    What have you tried?

    Please share your code.


  • Builds.init = function (data, callback) {
    
    	function renderPage(req, res, next) {
    		const buildData = {};
    		let data = {
    			title: "TMM",
    			build: buildData,
    			front: true,
    			relative_path: nconf.get("relative_path")
    		};
    		var template = 'front/build';
    		res.render(template, data);
    	};
    	data.router.get('/api/build/:bid', renderPage);
    	data.router.get('/build/:bid', data.middleware.buildHeader, renderPage);
    }
    

    Even when I manually call from browser /api/build/:bid route - it returns me data for render, so route works, but on click for the link - no results

  • Global Moderator

    Can you give an example of a link which exhibits the behavior you're talking about?


  • part of another page rendered html with a link
    <a class="c-slideset__photo" href="/build/34">
    <img src=/assets/plugins/nodebb-plugin-custom-auth-questions/images/photo/5.png" alt="image">

  • Global Moderator

    So it works when you load /build/34 directly in your browser, and it works when you load /api/build/34 directly in your browser, but it doesn't work when you click on the link.

    Are there any errors in the browser console or server log?


  • no errors in logs.
    I have found the issue. After digging into the nodebb routing and rendering I found this line in ajaxify.js

    $('#content').html(translatedTemplate);
    

    and understood that I am using my custom theme without element with id = content, that was a problem.
    After adding 'id=content' to my body tag in header template everything become Ok)
    @PitaJ Thanks for support

Suggested Topics

| |