random_split splits Datasets and returns Datasets, so trainloader and testloader should be of type Dataset not DataLoader.
The recommended way is your second approach: split the Datasets first, then wrap them in a DataLoader.