1
votes

I have 4 views and the main view is the login page. So when user click login button with correct credentials it will redirect to main page. But I received an error Can not navigate to route with name main because the route does not exist

Below is my manifest.json routing config:

    "routing": {
        "config": {
            "routerClass": "sap.m.routing.Router",
            "viewType": "XML",
            "async": true,
            "viewPath": "UI.sap_portal.view",
            "controlAggregation": "pages",
            "controlId": "app",
            "clearControlAggregation": false,
            "transition": "slide" 
        },
        "routes": [
            {
                "name": "Routemain",
                "pattern": "Routemain",
                "target": [
                    "Targetmain"
                ]
            } 
        ],
        "targets": {
            "Targetmain": {
                "viewType": "XML",
                "transition": "slide",
                "clearControlAggregation": false,
                "viewId": "login",
                "viewName": "login",
                "viewLevel": 1
            },
            "main": {
                "viewId": "main",
                "viewType": "XML",
                "viewName": "main",
                "viewLevel": 1
            },
            "masterData": {
                "viewType": "XML",
                "viewName": "masterData"
            },
            "purchasing": {
                "viewType": "XML",
                "viewName": "purchasing"
            } 
        }
    }

This is my login.controller.js code:

        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
        oRouter.navTo("main");

If I put this in my manifest.json

        "routes": [
            {
                "name": "Routemain",
                "pattern": "Routemain",
                "target": [
                    "Targetmain"
                ]
            },
            {
                "name": "main",
                "pattern": "",
                "target": "main"
            }

        ]

It auto redirect to my main page, it should be login page. Sorry I'm new with sapui5.

2

2 Answers

0
votes

Try changing the target for main into : "main": { "viewType": "XML", "viewName": "main" }

0
votes

The name of your route is Routemain. That’s what you should use on navTo: navTo(“Routemain”).

This will load the view defined in Targetmain.

You don’t have a route named “main” hence the error.